Issue
When I am defining my model as -
@Entity
@Table
public class User{
@Id
@NotNull
private String employeeId;
}
I am getting this error -
Caused by: org.postgresql.util.PSQLException: ERROR: column user0_.employeeid does not exist
but when I am using this -
@Entity
@Table(name = "`User`")
public class User{
@Id
@NotNull
@Column(name = "`employeeId`")
private String employeeId;
}
In my 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}
Why I am getting error in first one ? I don't want to specifically tell the names, spring boot jpa should automatically find the table and column by naming.
My tables and columns are same as my naming of entity and column, I don't want to change in the name, that's why I am using PhysicalNamingStrategyStandardImpl
What's wrong with 1st one ?
Solution
Actually, you should avoid to use upper case table or column names. But if you do not want to change it you can tell hibernate to use global quoting:
<property name="hibernate.globally_quoted_identifiers" value="true" />
Answered By - SternK