-->
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.  [ 6 posts ] 
Author Message
 Post subject: Contraint names
PostPosted: Mon Feb 09, 2004 2:47 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:04 pm
Posts: 64
Location: Melbourne, Australia
I notice that (at least for SQL Server) the constraint names aren't exactly meaningful:

Code:
alter table SVD_CONTENTDOCUMENTCATEGORY add constraint FK1355E574C4195AD9 foreign key (CategoryId) references SVD_SEAVIEWCONTENT;


How are these names generated? Will they be consistent across runs of SchemaExport? From my experiments it seems to be the case but I'd like to know how the name is picked.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2004 6:04 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Checking the sources will give you the fastest answer.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2004 6:59 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:04 pm
Posts: 64
Location: Melbourne, Australia
I guess I was being a bit lazy. The answer for anyone who's interested:

The FK names are calculated by taking a hash of table name and column names. Here's the code snippet:

Table.java:
Code:
   public String uniqueColumnString(Iterator iterator) {
      int result = 0;
      while ( iterator.hasNext() ) result += iterator.next().hashCode();
      return ( Integer.toHexString( name.hashCode() ) + Integer.toHexString(result) ).toUpperCase();
   }


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 1:15 pm 
Newbie

Joined: Mon Nov 22, 2004 1:04 pm
Posts: 5
Location: Denver, CO
In regards to the naming of constraints, is there a way to override the hash function and specify a constraint name in the hbm.xml file?

Thanks,
Chad


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 1:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
We always thought about making this overideable by using a NamingStrategy - it was never implemented though :) Patches are welcome.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 1:29 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There is a foreign-key="foo" mapping attribute, check the SchemaExport documentation chapter in the reference guide.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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