Column Name Annotation Ignored in Spring Boot JPA
Problem:
Despite using column annotations in Spring Boot applications with data-jpa dependency, the generated SQL table column names differ from the annotations.
Cause:
This behavior is typically caused by the hibernate dialect used. In versions prior to Hibernate 5, Hibernate uses a default naming strategy that prefixes column names with an underscore. To override this strategy, you need to explicitly specify the naming strategy.
Solution:
For Hibernate 4:
Set the spring.jpa.hibernate.naming_strategy property to org.hibernate.cfg.EJB3NamingStrategy:
<code class="properties">spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy</code>
For Hibernate 5:
Add the following lines to your application.properties file:
<code class="properties">spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl</code>
By using these settings, Hibernate will adopt a naming strategy that respects the column annotations specified in your entities.
The above is the detailed content of Here are a few title options, emphasizing the question and problem: Short & Direct: * Why Are My Column Annotations Ignored in Spring Boot JPA? * Spring Boot JPA: Column Names Not Matching. For more information, please follow other related articles on the PHP Chinese website!