-->
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.  [ 4 posts ] 
Author Message
 Post subject: NamingStrategy for foreign keys doesn't work
PostPosted: Thu Sep 25, 2008 3:54 am 
Newbie

Joined: Tue Mar 21, 2006 5:22 am
Posts: 5
Hello,
I want to replace generated foreign key names (FK + hash(table name) + hash(column name)) with my custom names.

I created new NamingStrategy class with foreignKeyColumnName() method but without efect to resultant foreign key names.

I see in log that my NamingStrategy is used (Using com.anect.rmt.utils.CustomNamingStrategy as naming strategy).

I use Hibernate 3.3.1 with JPA.

Here is my configuration of ANT task:
Code:
       <hibernatetool destdir="${output.schema.dir}"> 
          <classpath refid="classpathDefault" />
          <annotationconfiguration configurationfile="hibernate.cfg.xml " namingstrategy="com.anect.rmt.utils.CustomNamingStrategy" /> 
          <hbm2ddl 
              drop="true" 
              create="true" 
              export="false" 
              outputfilename="schema-ddl.sql" 
              delimiter=";" 
              format="true"/> 
      </hibernatetool> 


I have also used jpaconfiguration but with the same result. I can change table names for example but not foreign keys.

Please what's wrong?

Thank you in advance,
PETER


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 6:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
foreignKeyColumnName does not relate to foreign key names, but to the columns in the foreign keys.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 26, 2008 1:32 am 
Newbie

Joined: Tue Mar 21, 2006 5:22 am
Posts: 5
Oooh, good misunderstanding :(.

And is there possibility how to change foreign keys apart from @ForeignKey annotation?

@ForeignKey is good solution but not for this case:
Code:
public class BussinesValue {
  @ManyToOne(optional = false)
  @JoinColumn(name = "avail_level_id", nullable = false) 
  @ForeignKey(name = "avail_level_fk")
  private AvailabilityLevel availability;
  ...
}

Code:
public class Asset {
  @Embedded
  private BussinesValue value;
  ...
}

Code:
public class AssetGroup {
  @Embedded
  private BussinesValue value;
  ...
}


Then will be duplicate foreign key names in database...

Thank you in advance,
PETER


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 26, 2008 12:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ask in annotations forum and if it is a bug report it in jra.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.