Spring Boot + JPA : Column name annotation ignored
For Hibernate 5, I solved this issue by adding the following lines in my application.properties file:
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Spring Boot (5) JPA : Column name annotation fails (with set naming convention)
Turns out the context of my application was being bypassed as I was not using all of spring boot and partially creating my own context. Rebuilding the context to work more in line with spring boot made it pick up the proper configuration from applicatiom.yml.
How to prevent Spring Boot/Hibernate from converting entity column names from PascalCase to snake_case?
in your project application.properties
file set the naming strategy:
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.EJB3NamingStrategy
Default value is org.springframework.boot.orm.jpa.SpringNamingStrategy
UPDATE:
If previous property does not solved your problem, you can use this one (For newer versions of Hibernate):
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Wrong column name even if specified
In SpringBoot the @Column(name="")
annotation is ignored unless you set an application property to use a different naming class.
If you don't have an application.properties
, make a file by that name in your src/main/resources
directory. Add the line:
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
In it and your naming will work as you want it.
Reference: Spring Boot + JPA : Column name annotation ignored
Spring Data doesn't seem to understand @Column name
By default Spring uses jpa.SpringNamingStrategy
to generate the table names.
The ImprovedNamingStrategy
will convert CamelCase
to SNAKE_CASE
where as the EJB3NamingStrategy
just uses the table name unchanged.
You can try to change the naming_strategy
to:
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
or the @Column name
attribute should be in lowercase @Column(name = "firstname")
For Hibernate 5
this should work (I am not quite sure if you also need the above one. But try it with both):
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
JPA '.'(dot) in column name
Fixed this by add the following to application.properties
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Referenced from this answer
https://stackoverflow.com/a/48442812/8277643
How does JPA map a column name to a field if the column name is different than the field name?
You may use the @Column
annotation, e.g.
@Entity(name="Students")
public class Students {
@Column(name = "firstname")
private String fname;
@Column(name = "lastname")
private String lname;
}
Related Topics
Date Object Simpledateformat Not Parsing Timestamp String Correctly in Java (Android) Environment
Android Changing Floating Action Button Color
Setting Custom Actionbar Title from Fragment
How to Call JavaScript from Android
Opengl Es2 Alpha Test Problems
Gradle - What Is a Non-Zero Exit Value and How to Fix It
Android: How to Stretch an Image to the Screen Width While Maintaining Aspect Ratio
How to Make a Copy of a File in Android
Transitive Dependencies Not Resolved for Aar Library Using Gradle
How to Update a Textview of an Activity from Another Class
Java.Io.Console Support in Eclipse Ide
Jersey /* Servlet Mapping Causes 404 Error for Static Resources