-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Foreign key column name strategy for Hibernate >= 5.x ?
PostPosted: Wed Mar 09, 2016 9:21 am 
Newbie

Joined: Wed Mar 09, 2016 8:58 am
Posts: 1
For Hibernate < 5.x I implemented the following naming strategy which converts all names to lower case and uses the format "foreigntablename_referencedcolumnname" for foreign key columns:
Code:
public class LowerCaseDefaultNamingStrategy extends DefaultNamingStrategy {
...
@Override
   public String foreignKeyColumnName(String propertyName, String propertyEntityName, String propertyTableName, String referencedColumnName) {
      String foreignKeyColumnName = new StringBuffer(propertyTableName).append("_").append(referencedColumnName).toString().toLowerCase();
      return foreignKeyColumnName;
   }
...
}


In Hibernate >= 5.x one can use PhysicalNamingStrategy for the lower case names part, works fine. But I can't figure out how/where (ImplicitNamingStrategy?) to replace/implement the method above so that foreign key column names are converted to the mentioned format.
Any hints would be greatly appreciated.

Cheers


Top
 Profile  
 
 Post subject: Re: Foreign key column name strategy for Hibernate >= 5.x ?
PostPosted: Wed Mar 09, 2016 9:28 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You can supply an ImplicitNamingStartegy via the "hibernate.implicit_naming_strategy" onfiguration property.

The ImplicitNamingStartegy allows you to customize the FK column name through the "determineForeignKeyName" method.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.