Entity Class name is transformed into SQL table na

2019-01-18 08:47发布

I have the following entity defined:

@Entity
@Table(name = "EmailTemplate")
public class EmailTemplate {

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?

Edit:

I'm using Spring Boot: start JPA. From my build.gradle file,

compile("org.springframework.boot:spring-boot-starter-data-jpa")

5条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-18 08:53

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.

查看更多
forever°为你锁心
3楼-- · 2019-01-18 09:06

Use

spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.DefaultNamingStrategy
查看更多
Evening l夕情丶
4楼-- · 2019-01-18 09:10

For hibernate v5:

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
查看更多
劫难
5楼-- · 2019-01-18 09:11
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a];     
nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement

Both are required :

implicit-strategy 
physical-strategy
查看更多
迷人小祖宗
6楼-- · 2019-01-18 09:12

Solved.

Invalid Object Name: Springboot with JPA(SQL server)

In application.yaml/properties specify the

spring.jpa.hibernate.naming.implicit-strategy spring.jpa.hibernate.naming.physical-strategy

jpa: show-sql: false hibernate: ddl-auto: none # Defaults to "none" when NOT in embedded mode naming: implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

查看更多
登录 后发表回答