0

I have my entity called invoice and a column with the name "convenioPago" in the database but cannot find it

try to put @Column (name = "\"convenioPago\"", nullable = false) but still with the same error

@Entity
@Table(name = "invoice", schema = "public")
public class Invoice {
 //more columns
 @Column (name = "\"convenioPago\"", nullable = false)
 private Long convenioPago;
}

I also use @Configuration to create my datasource

@EnableJpaRepositories(basePackages = {"package.repository"})
@Configuration
public class Config {
 @Bean
 public DataSource dataSource(){
   DriverManagerDataSource dataSource = new DriverManagerDataSource();
   //use org.postgresql.Driver
 }

Note: I use spring-boot-starter-parent 2.1.7.RELEASE

The error I have is: ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper: ERROR: column invoice0.convenio_pago does not exist

Because it refers to convenio_pago if it should be to convenioPago?

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
Maicoly Morocho
  • 149
  • 1
  • 14
  • Which RDBMS you are using? – Youcef LAIDANI Sep 10 '19 at 05:04
  • Hi @YCF_L I use Relational – Maicoly Morocho Sep 10 '19 at 05:07
  • I mean MySQL, PostgreSQL, Oracle, also can you show us how you create the table please – Youcef LAIDANI Sep 10 '19 at 05:11
  • ooh! sorry I use POSTGRES, the table was created many years ago using MyEclipseCI but I have a microservices project with that table and I mapped it. The entity is https://textsaver.flap.tv/lists/2v97 – Maicoly Morocho Sep 10 '19 at 05:20
  • check this https://stackoverflow.com/questions/36353492/jpa-uppercase-table-names – Youcef LAIDANI Sep 10 '19 at 05:24
  • Hi @YCF_L I use `org.hibernate.dialect.PostgreSQL9Dialect` in my application.yml. I also mentioned that my datasource is from `@Configuration` – Maicoly Morocho Sep 10 '19 at 05:30
  • 1
    Check this https://stackoverflow.com/questions/376093/hibernate-column-name-issues/376118. Also, Hibernate is doing what's perferred. Still, you could enclose your column name in extra quotes to acheive what you need – Yogesh Patil Sep 10 '19 at 05:38
  • Possible duplicate of [Spring Boot Hibernate 5 Ignoring @Table and @Column](https://stackoverflow.com/questions/41912028/spring-boot-hibernate-5-ignoring-table-and-column) – Martin van Wingerden Sep 10 '19 at 05:48
  • Hi @YogeshPatil my application.yml is: https://textsaver.flap.tv/lists/2v9a. I use `org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl` – Maicoly Morocho Sep 10 '19 at 05:51
  • Hi, @MartinvanWingerden, his answer is almost solving me, now he doesn't show me the "_", the output now is that he doesn't find `conveniopago` but it should be `convenioPago` – Maicoly Morocho Sep 10 '19 at 06:34

2 Answers2

0

If you're using Hibernate native API, then you can escape them using backticks:

@Column(name = "`convenioPago`")
private Long convenioPago;
Jonathan JOhx
  • 5,784
  • 2
  • 17
  • 33
0

Thanks @MartinvanWingerden, your comment helped me to the solution! My solution: In my @Configuration, i need this jpaproperties.

Properties jpaProperties = new Properties();
jpaProperties.put("hibernate.ejb.naming_strategy","org.hibernate.cfg.ImplicitNamingStrategy");
jpaProperties.put("hibernate.ejb.physical_naming_strategy","org.hibernate.cfg.PhysicalNamingStrategyImpl");

and the dialect:

jpaProperties.put("hibernate.dialect","org.hibernate.dialect.PostgreSQLDialect");
Maicoly Morocho
  • 149
  • 1
  • 14