Spring Boot JPA 中忽略列名注释
问题:
尽管使用列注释在具有 data-jpa 依赖项的 Spring Boot 应用程序中,生成的 SQL 表列名称与注释不同。
原因:
此行为通常是由 hibernate 方言引起的用过的。在 Hibernate 5 之前的版本中,Hibernate 使用默认命名策略,在列名称前添加下划线。要覆盖此策略,您需要显式指定命名策略。
解决方案:
对于 Hibernate 4:
将 spring.jpa.hibernate.naming_strategy 属性设置为 org.hibernate.cfg.EJB3NamingStrategy:
<code class="properties">spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy</code>
对于 Hibernate 5:
将以下行添加到application.properties 文件:
<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>
通过使用这些设置,Hibernate 将采用尊重实体中指定的列注释的命名策略。
以上是以下是一些标题选项,强调问题和问题: 简短和直接: * 为什么我的列注释在 Spring Boot JPA 中被忽略? * Spring Boot JPA:列名称不匹配的详细内容。更多信息请关注PHP中文网其他相关文章!