实体类名称转换为带下划线的SQL表名称 [英] Entity Class name is transformed into SQL table name with underscores
问题描述
我定义了以下实体:
@Entity
@Table(name = "EmailTemplate")
public class EmailTemplate {
尽管有表注释,但我收到了java.sql.SQLException: Invalid object name 'email_template'
.如何防止将诸如EmailTemplate之类的实体类转换为email_template表名?
Despite the table annotation, I receive java.sql.SQLException: Invalid object name 'email_template'
. How can I prevent an entity class such as EmailTemplate being transformed into email_template table name?
我正在使用Spring Boot:启动JPA.在我的build.gradle文件中,
I'm using Spring Boot: start JPA. From my build.gradle file,
compile("org.springframework.boot:spring-boot-starter-data-jpa")
推荐答案
默认情况下,Spring使用org.springframework.boot.orm.jpa.SpringNamingStrategy
来分隔驼峰名称并使用下划线.尝试在application.properties
中设置spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.EJB3NamingStrategy
.查看此和
Spring by default uses org.springframework.boot.orm.jpa.SpringNamingStrategy
which splits camel case names with underscore. Try setting spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.EJB3NamingStrategy
in application.properties
. Check out this and this for more info.
这篇关于实体类名称转换为带下划线的SQL表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!