'hibernate column name issues
@Column(name="DateOfBirth")
private Date dateOfBirth;
I specifically need the above code to create a column named "DateOfBirth," instead Hibernate gives me a column named date_of_birth. How can I change this? Is there a web.xml property? I came across DefaultNamingStrategy and ImprovedNamingStrategy, but not sure how to specify one or the other.
Solution 1:[1]
Try putting this in
application.properties
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Solution 2:[2]
FYI: The reason for the insertion of underscores is probably because you're using an ImprovedNamingStrategy. It's set on your Configuration object. See here for an example...
If you don't want the underscores you can just not set the naming strategy, or set it to the DefaultNamingStrategy you discovered earlier.
Solution 3:[3]
add below property in the case of spring boot.
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Solution 4:[4]
Put the @Column annotation on the getter:
@Column(name="DateOfBirth")
public Date getDateOfBirth() {
...
}
Solution 5:[5]
The workaround proposed was to use @Column(name="dateofbirth"), which worked for my purposes.
Solution 6:[6]
ImprovedNamingStrategy has method addUnderscores() which is called from tableName() and columnName() you can implement your own naming strategy class and override these as per your choice
public class MyOwnNamingStrategy extends ImprovedNamingStrategy {
@Override
public String tableName(String tableName) {
//return addUnderscores(columnName); // skip this
return columnName; // if you want column name variable name same
//return changeAsYouWant(columnName); // as name sames
}
}
Solution 7:[7]
You can annotate either fields or getter methods, it doesn't make a difference. Can you post your full hibernate.cfg.xml or persistence.xml file?
Solution 8:[8]
I'm not 100% sure, but don't you need to annotate the get method and not the private variable?
Solution 9:[9]
I had a similar problem and adding the following two properties to my application.properties solved my issue: spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl .
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rahul Singh |
| Solution 2 | |
| Solution 3 | ErSyyedS |
| Solution 4 | Ryan Anderson |
| Solution 5 | lucas |
| Solution 6 | jonsca |
| Solution 7 | cliff.meyers |
| Solution 8 | davetron5000 |
| Solution 9 | Mateusz K. |
