简体   繁体   English

如何防止 Spring Boot/Hibernate 将实体列名称从 PascalCase 转换为 snake_case?

[英]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.

相关问题 除非明确指定,否则如何在默认情况下将 Spring Data JPA 从 camelCase 命名为 snake_case? - How to make Spring Data JPA by default naming from camelCase to snake_case unless explicitly specified? Java中从snake_case到camelCase - From snake_case to camelCase in Java 如何 map Hibernate 实体字段使用camelCase到snake_case(下划线)数据库标识符 - How to map Hibernate entity fields using camelCase to snake_case (underscore) database identifiers Jackson / Spring Boot - 将 snake_case model 序列化为 camelCase - Jackson / Spring Boot - serialize a snake_case model to camelCase 将Jackson配置为在Spring Boot 2.0.0.M1中“全局”使用SNAKE_CASE - Configure Jackson to use SNAKE_CASE “globally” in Spring Boot 2.0.0.M1 JAVA - 不使用 ObjectMapping 和 SetPropertyNamingStrategy 将 CamelCase 转换为 Snake_Case - SNAKE_CASE - JAVA - Not converting CamelCase to Snake_Case using ObjectMapping and SetPropertyNamingStrategy - SNAKE_CASE 如何解析 SnakeYAML 中的 snake_case 属性 - How to parse snake_case properties in SnakeYAML Hibernate/Spring Boot:如何从回滚中排除实体 - Hibernate/Spring Boot: How to exclude an entity from rollback 如何将firebase数据(snake_case)转换为Java对象(camelCase) - How to convert firebase data (snake_case) to Java object (camelCase) 如何在Java中将snake_case JSON转换为嵌套JSON? - How to convert a snake_case JSON to nested JSON in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM