英文:
@Table(name="camelCase") changes to snake_case:"camel_case"
问题
我有一个实体类,如下所示:
@Entity(name = "companyCode")
@Table(name = "companyCode")
public class CompanyCode {
@Id
@Column(name = "companyCode")
String cCode;
}
在 SQL 中,它创建的表名为 "company_code" 而不是 "companyCode"。列名也被创建为 "company_code"。
是否有办法以驼峰命名法(camelCase)而不是蛇形命名法(snake_case)创建表和列?
Java 版本:11
Spring Boot 版本:2.7.0
Spring Data JPA 版本:最新版
英文:
I have an entity class as follows:
@Entity(name = "companyCode")
@Table(name = "companyCode")
public class CompanyCode {
@Id
@Column(name = "companyCode")
String cCode;
}
Instead of creating the table name as companyCode in sql it creates the table as "company_code". The column name is also created as "company_code".
Is there any way to create the table and column using camelCase instead of snake case?
Java Version: 11
Spring Boot version: 2.7.0
Spring Data JPA Version: Latest
答案1
得分: 2
找到答案。
在应用属性中设置Hibernate的命名策略如下:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
英文:
FOUND THE ANSWER.
Set naming strategy in hibernate in application property as
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
link for reference:
https://stackoverflow.com/questions/26711323/unable-to-set-namingstrategy-using-spring-boot-gorm-gradle
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论