【发布时间】:2021-02-09 18:24:26
【问题描述】:
当我将我的模型定义为 -
@Entity
@Table
public class User{
@Id
@NotNull
private String employeeId;
}
我收到此错误 -
Caused by: org.postgresql.util.PSQLException: ERROR: column user0_.employeeid does not exist
但是当我使用这个时-
@Entity
@Table(name = "`User`")
public class User{
@Id
@NotNull
@Column(name = "`employeeId`")
private String employeeId;
}
在我的 application.yml -
spring:
jpa:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
ddl-auto: update
database-platform: org.hibernate.dialect.PostgreSQLDialect
datasource:
url: ${db.host}
username: ${db.user}
password: ${db.password}
为什么我在第一个中遇到错误?具体名字我就不说了,spring boot jpa应该会自动通过命名找到表和列。
我的表和列与我对实体和列的命名相同,我不想更改名称,这就是我使用PhysicalNamingStrategyStandardImpl
第一个有什么问题?
【问题讨论】:
-
你使用
hibernate.globally_quoted_identifiers属性吗? -
@SternK 不,我没用过
-
@SternK 正如你所看到的,它正在寻找
user0_.employeeid但它应该是user0_.employeeId它是两个小写字母 -
@SternK 我用
true试过了,现在它工作了!!谢谢 !您可以将其发布为答案
标签: spring spring-boot hibernate jpa