-->
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: Natural keys using a composite-id best practices?
PostPosted: Thu Aug 04, 2005 10:27 am 
Beginner
Beginner

Joined: Tue Jul 12, 2005 10:27 am
Posts: 23
We are using natural keys in our data model and I was wondering what are healthy best practices? What makes our case a little unique is that we have other entity objects that share common columns in the primary key, plus an additional column or two.

If the child object has reference to its parent, then using the foreign generator would inherit the parents primary key values.

Example:

<id name="key" type="somepackage.Key" >
<column name="column1_id" />
<column name="column1_id" />
<generator class="foreign" >
<param name="property">parent</param>
</generator>
</id>


Thank you,

_________________
- Richard Burton


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 10:39 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Generally speaking, if you have influence on your data model, use surrogate keys, which certainly is a best practice.

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 10:42 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Good (and there are quite a few restrictions on that) natural keys are fine, even as primary keys. Composite primary keys should be avoided if no good single-column candidate key exists and a surrogate primary key should be used.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 11:18 am 
Beginner
Beginner

Joined: Tue Jul 12, 2005 10:27 am
Posts: 23
In this case we have no choice and to have the database remodeled is not an option. I myself prefer surrogate keys for many reasons. With that being said, what are some good coding standards, designs, etc. when using composite keys? E.g., use a Composite key object, etc

Are there really any good tips related to this subject besides that? I haven’t found anything worth while on the forum.

_________________
- Richard Burton


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.