提问者:小点点

我的表@Entity@column中不存在列


我有一个名为发票的实体和数据库中名为“方便帕戈”的列,但找不到它

尝试将@Column(name=“\”conventioPago\“”,nullable=false)放入,但仍有相同的错误

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

我还使用@配置来创建我的数据源

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

注意:我使用 spring-boot-starter-parent 2.1.7.RELEASE

我的错误是:ERRORorg.hibernate.engine.jdbc.spi.SqlExceptionHelper: ERROR:列invoice0.convenio_pago不存在

因为它引用了< code>convenio_pago,如果它应该引用< code>convenioPago的话?


共2个答案

匿名用户

如果您使用的是Hibernate本地API,那么您可以使用反勾号来转义它们:

@Column(name = "`convenioPago`")
private Long convenioPago;

匿名用户

感谢@MartinvanWingerden,您的评论帮助我找到了解决方案!我的解决方案:在我的@配置中,我需要这个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");

和方言:

jpaProperties.put("hibernate.dialect","org.hibernate.dialect.PostgreSQLDialect");