Hibernate field naming issue with Spring Boot (naming strategy)
SINCE SPRING-BOOT 1.4
Starting from 1.4, because of the switch to Hibernate 5, the naming strategy has been updated to SpringPhysicalNamingStrategy
which should be very close to 1.3 defaults.
See also:
- Spring's naming strategy
PREVIOUS VERSION
Spring Boot provides the ImprovedNamingStrategy
as default naming strategy, which makes Hibernate search for a team_id
column (inferred from the int teamId
field). As this column doesn't exist in your table, that's the cause of the error. From the Hibernate docs:
An improved naming strategy that prefers embedded underscores to mixed case names
You've got two options:
Provide the column name explicitly as
@Column(name="teamId")
. There used to be a bug with this in early Boot versions, not anymore.Change the naming strategy in the Spring Boot properties and tell it to use the
EJB3NamingStrategy
, which doesn't convert camelCase to snake_case, but keeps it as it is.
If you are using Spring Boot 2.0.2 and Hibernate 5.3.4 then setting the following property will fix the issue.
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Below strategy worked for me
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.DefaultComponentSafeNamingStrategy