Entity Class name is transformed into SQL table name with underscores

James picture James · Mar 16, 2015 · Viewed 48.6k times · Source

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")

Answer

Predrag Maric picture Predrag Maric · Mar 16, 2015

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.