Spring Boot + JPA : Column name annotation ignored

ghz 1years ago ⋅ 3659 views

Question

I have a Spring Boot application with dependency spring-boot-starter-data- jpa. My entity class has a column annotation with a column name. For example:

@Column(name="TestName")
private String testName;

Despite this, SQL generates test_name as the column's name. After looking for a solution I have found that setting spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy solves the problem (the column name is taken from the column annotation).

Still, my question is: why without naming_strategy set to EJB3NamingStrategy is JPA ignoring the column annotation? Maybe the hibernate dialect has something to do with it? I'm connecting to MS SQL 2014 Express and my logs contain:

Unknown Microsoft SQL Server major version [12] using SQL Server 2000 dialect
Using dialect: org.hibernate.dialect.SQLServerDialect 

Answer

For Hibernate 5, I solved this issue by adding the following lines in my application.properties file:

spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl