-->
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.  [ 3 posts ] 
Author Message
 Post subject: Auto generated foreign key name
PostPosted: Wed Jun 11, 2008 10:53 am 
Newbie

Joined: Wed Jun 11, 2008 10:47 am
Posts: 2
Hi

I have looked around on the net and even put some output in the hibernate source to try and understand how the name for a foreign key is generated for example "fkb96df9aa146a5373".

Our problem is that when we deploy with hbm2ddl auto set to update duplicated foreign key constraints with different ID's but are mapping the same columns. We wanted to understand how the name was generated so that each time the same name would be generated hence not creating duplicate constraints

Thanks for any help in advance.

Cheers

Daniel Lees
(Senior Software Engineer)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 12:06 pm 
Newbie

Joined: Wed Jun 11, 2008 10:47 am
Posts: 2
I think i might have found something, is it:

hexString of a hash of the table name plus the hexString of the sum of the hashes of all the columns in the parent table? The bit of code below?

while ( iterator.hasNext() ) {
result += iterator.next().hashCode();
}

( Integer.toHexString( name.hashCode() ) + Integer.toHexString( result ) )


If this is the case does any1 know why when a new column is added there is the need to create a new name for an existing foreign key constraint? I would have thought that if the column has no relevance to the existing constraints then no new name would be needed?

Cheers

Daniel Lees


Top
 Profile  
 
 Post subject: Re: Auto generated foreign key name
PostPosted: Thu Jun 12, 2008 2:41 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
leesy84 wrote:
...the name for a foreign key is generated for example "fkb96df9aa146a5373".


Hi leesy84,

if you don't like these funny names, give foreign key constraints a self defined name; i.e:

Code:
@org.hibernate.annotations.ForeignKey(name="FK_INSTITUT_PARTY_ID")


Carlo


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