5

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.

Mike
  • 2,354
  • 3
  • 23
  • 37

2 Answers2

4

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.

gkamal
  • 20,777
  • 4
  • 60
  • 57
  • the parameter received in logicalCollectionColumnName already contains column_id if I use EJB3NamingStrategy but if I use ImprovedNamingStrategy the parameter doesn't receive it. I don't understand why. This method is called from somewhere else in the code. – Mike Oct 07 '11 at 17:34
  • Yeah your write, I wasn't looking the right method. The id part is commented – Mike Oct 07 '11 at 19:32
3

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 {}
Pankaj
  • 615
  • 5
  • 9