Naming Strategy with foreign keys referenced entity

66 views
Skip to first unread message

JavaPlayer

unread,
Oct 7, 2011, 12:28:16 PM10/7/11
to play-framework
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.

JavaPlayer

unread,
Oct 7, 2011, 3:33:29 PM10/7/11
to play-framework
Ok you need to override the ImprovedNamingStrategy because they
commented the part that the add the primary key of the referenced
table:

public String foreignKeyColumnName(
String propertyName, String propertyEntityName, String
propertyTableName, String referencedColumnName
) {
String header = propertyName != null ?
StringHelper.unqualify( propertyName ) : propertyTableName;
if (header == null) throw new AssertionFailure("NamingStrategy not
properly filled");
return columnName( header ); //+ "_" + referencedColumnName not used
for backward compatibility
Reply all
Reply to author
Forward
0 new messages