@Table(name=”camelCase”) changes to snake_case:”camel_case”

huangapple go评论55阅读模式
英文:

@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"。

MySQL 中的表:
@Table(name=”camelCase”) changes to snake_case:”camel_case”

是否有办法以驼峰命名法(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".

Table in mysql:
@Table(name=”camelCase”) changes to snake_case:”camel_case”

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

参考链接:
https://stackoverflow.com/questions/26711323/unable-to-set-namingstrategy-using-spring-boot-gorm-gradle

英文:

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

huangapple
  • 本文由 发表于 2023年6月5日 20:26:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76406404.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定