Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Class name is transformed into SQL table name with underscores

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") 
like image 640
James Avatar asked Mar 16 '15 21:03

James


People also ask

What is @entity annotation in spring boot?

The @Entity annotation specifies that the class is an entity and is mapped to a database table. The @Table annotation specifies the name of the database table to be used for mapping.

What is the difference between @entity and @table in hibernate?

Entity means the class which you will use in your program and Table means the actual Database table that you will access through your program. Hibernate being an ORM requires you to declare the relationship between the tables and the classes mapping to them.

What is Spring JPA Hibernate naming physical strategy?

Hibernate uses the Physical Naming Strategy to map our logical names to a SQL table and its columns. By default, the physical name will be the same as the logical name that we specified in the previous section. If we want to customize the physical names, we can create a custom PhysicalNamingStrategy class.


1 Answers

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.

like image 86
Predrag Maric Avatar answered Sep 21 '22 19:09

Predrag Maric