[英]How to prevent Spring Boot/Hibernate from converting entity column names from PascalCase to snake_case?
I stumbled upon a strange error today.我今天偶然发现了一个奇怪的错误。 One of my Java Persistence Application programming interface (JPA) entities in Spring Boot application is not working.我的 Spring 引导应用程序中的一个 Java 持久性应用程序编程接口 (JPA) 实体之一不工作。 I tracked the problem down to a single column:我将问题追踪到一列:
@javax.persistence.Column(name = "NameWrittenInPascalCase")
java.lang.String c;
When I checked the Structured Query Language (SQL) query which Spring Boot/Hibernate generates I discovered the problem.当我检查 Spring Boot/Hibernate 生成的结构化查询语言 (SQL) 查询时,我发现了问题。 It seams that Spring Boot or Hibernate converts the NameWrittenInPascalCase
into name_written_in_pascal_case
(just written in snake case).它接缝 Spring Boot 或 Hibernate 将NameWrittenInPascalCase
转换为name_written_in_pascal_case
(只是写在蛇案例中)。 (In database, of course, my column name is written in PascalCase). (当然,在数据库中,我的列名是用 PascalCase 写的)。
For gods sake, why?看在上帝的份上,为什么?
And how to prevent it from doing so?以及如何防止它这样做?
If you need aditional info, I use Spring Boot version 2.5.7.如果您需要其他信息,我使用 Spring 引导版本 2.5.7。
in your project application.properties
file set the naming strategy:在您的项目application.properties
文件中设置命名策略:
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.EJB3NamingStrategy
Default value is org.springframework.boot.orm.jpa.SpringNamingStrategy
默认值为org.springframework.boot.orm.jpa.SpringNamingStrategy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.