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")
Spring by default uses
org.springframework.boot.orm.jpa.SpringNamingStrategy
which splits camel case names with underscore. Try settingspring.jpa.hibernate.naming-strategy=org.hibernate.cfg.EJB3NamingStrategy
inapplication.properties
. Check out this and this for more info.Use
For hibernate v5:
Both are required :
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