Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EJB3NamingStrategy vs ImprovedNamingStrategy Foreign Key Naming

Tags:

java

hibernate

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.

like image 370
Mike Avatar asked Oct 07 '11 15:10

Mike


People also ask

What is ImprovedNamingStrategy?

ImprovedNamingStrategy , which will convert the mixed case names to the embedded underscores name .

What is Naming strategy in hibernate?

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.

What is PhysicalNamingStrategy?

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.

What is Spring JPA Hibernate naming strategy?

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.


2 Answers

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.

like image 77
gkamal Avatar answered Nov 15 '22 03:11

gkamal


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 {}
like image 28
Pankaj Avatar answered Nov 15 '22 04:11

Pankaj