Spring Boot + JPA:忽略列名称注释 [英] Spring Boot + JPA : Column name annotation ignored
问题描述
我有一个Spring Boot应用程序,具有依赖关系spring-boot-starter-data-jpa。我的实体类具有列名称的列注释。例如:
@Column(name =TestName)
private String testName;
由此创建的test_name作为列名产生的SQL。找到解决方案后,我发现 spring.jpa.hibernate.naming_strategy = org.hibernate.cfg.EJB3NamingStrategy
解决了问题(列名取自列注释)。
不过,我的问题是为什么没有将naming_strategy设置为 EJB3NamingStrategy
JPA忽略列注释?冬眠方言可能与它有关吗?我连接到MS SQL 2014 Express,我的日志中包含:
未知Microsoft SQL Server主要版本[12]使用SQL Server 2000方言
使用方言:org.hibernate.dialect.SQLServerDialect
spring.jpa。 hibernate.naming.implicit-strategy = org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy = org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
I have a Spring Boot application with dependency "spring-boot-starter-data-jpa". My entity class has a column annotation with column name. For example:
@Column(name="TestName")
private String testName;
SQL generated by this created test_name as column name. After looking for solution I have found that spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
solved the problem (column name is taken from column annotation).
Still, my question is why without naming_strategy set to EJB3NamingStrategy
JPA is ignoring column annotation? Maybe hibernate dialect has something to do with it? I'm connecting to MS SQL 2014 Express and my logs contains:
Unknown Microsoft SQL Server major version [12] using SQL Server 2000 dialect
Using dialect: org.hibernate.dialect.SQLServerDialect
For hibernate5 I solved this issue by puting next 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
这篇关于Spring Boot + JPA:忽略列名称注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!