My naming strategy in hibernate was the default one : EJB3NamingStrategy. So the field and table names was in camelcase. I switched it to ImprovedNamingStrategy to have snakecase.
But my foreign keys doesn't include the primary key name of the referenced entity in the name.
Example:
table1: id name
With EJB3NamingStrategy the table2 fields will be:
table2: id table1_id
but with ImprovedNamingStrategy the table2 fields will be: table2: id table1
Is there a way to have _id with the ImprovedNamingStrategy. I don't understand why hibernate behave differently because the logicalCollectionColumnName method in both strategy are identical.
ImprovedNamingStrategy , which will convert the mixed case names to the embedded underscores name .
Implicit Naming StrategyHibernate uses a logical name to map an entity or attribute name to a table or column name. This name can be customized in two ways: it can be derived automatically by using an ImplicitNamingStrategy or it can be defined explicitly by using annotations.
The Hibernate PhysicalNamingStrategy methods allow you to customize the default naming conventions for the following database identifiers: toPhysicalCatalogName – customize the default database catalog naming convention. toPhysicalSchemaName – customize the default database schema naming convention.
naming. strategy ; Hibernate 5 defines a Physical and Implicit naming strategies. Spring Boot configures SpringPhysicalNamingStrategy by default. This implementation provides the same table structure as Hibernate 4: all dots are replaced by underscores and camel cases are replaced by underscores as well.
Extend the improvedNamingStrategy and customize, maybe the initial implementation of the ImprovedNamingStrategy got this wrong and then they couldn't fix it as it would break backward compatability.
This issue is resolved in spring boot 1.2.7.RELEASE. Reference of this thread is also specified in the documentation of the jpa hibernate package. Class signature as follows:
package org.springframework.boot.orm.jpa.hibernate;
public class SpringNamingStrategy extends ImprovedNamingStrategy {}
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