Spring Boot + JPA:列名注释被忽略 [英] Spring Boot + JPA : Column name annotation ignored
问题描述
我有一个依赖 spring-boot-starter-data-jpa
的 Spring Boot 应用程序.我的实体类有一个带有列名的列注释.例如:
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;
由此创建的test_name
生成的SQL 作为列名.在寻找解决方案后,我发现 spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
解决了这个问题(列名取自列注释).
SQL generated by this created test_name
as the columns name. After looking for a solution I have found that spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
solved the problem (column name is taken from column annotation).
不过,我的问题是为什么没有将naming_strategy 设置为EJB3NamingStrategy
JPA 会忽略列注释?也许冬眠方言与它有关?我正在连接到 MS SQL 2014 Express 并且我的日志包含:
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 contain:
Unknown Microsoft SQL Server major version [12] using SQL Server 2000 dialect
Using dialect: org.hibernate.dialect.SQLServerDialect
推荐答案
对于 Hibernate 5,我通过在 application.properties 文件中添加以下几行解决了这个问题:
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
这篇关于Spring Boot + JPA:列名注释被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!