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")
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With