-->
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.  [ 7 posts ] 
Author Message
 Post subject: composite versus surrogate keys. Opinions wanted!
PostPosted: Thu Jan 06, 2005 1:34 pm 
Newbie

Joined: Thu Jan 06, 2005 1:27 pm
Posts: 3
On the current project we have a division between two groups on what type of key structure we should use in the database.

I am on the side of using surrogate (also called natural keys) with hibernate or any database access tool.

Using surrogate keys is very simple in my java applications since hibernate takes care of the magic to persist the data. On ther other side, I have to create extra java code in order to build the key and persist.

I seek your opinion for either side of the case.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 06, 2005 1:37 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
If you think that a surrogate key is a natural key, you have something completely wrong.


Top
 Profile  
 
 Post subject: Re: composite versus surrogate keys. Opinions wanted!
PostPosted: Thu Jan 06, 2005 1:42 pm 
Newbie

Joined: Thu Jan 06, 2005 1:27 pm
Posts: 3
codiem wrote:
I am on the side of using surrogate (also called natural keys) with hibernate or any database access tool.


I realize my mistake in swtiching terminology I meant to say:

I am on the side of using surrogate with hibernate or any database access tool.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 06, 2005 2:08 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Which is a good idea for obvious reasons: stability, null-safe, durable, etc.

The question should be: what could natural keys possibly do better? I doubt that you will find many satisfying answers to that question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 06, 2005 3:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
christian wrote:
The question should be: what could natural keys possibly do better? I doubt that you will find many satisfying answers to that question.

Lazyness. It still happen to me... sometimes ;-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject: to use concatenated keys or not
PostPosted: Thu Jan 06, 2005 3:50 pm 
Newbie

Joined: Thu Jan 06, 2005 1:27 pm
Posts: 3
Natural vs surrogate has been widely debated and both sides have their point.


The real question is should a single key be used versus a concatenated key. For example:

Table 1
table_1_id PK (surrogate)

Table 2
table_2_id PK (surrogate)

Table 3
table_3_id PK (surrogate)

Table 4
table_1_id PK
table_2_id PK
table_3_id PK

NOTE: Table 4 is a composite key

Then if you want to create a relationship to table 4 you have to carry the three columns of the composite key.

Table 5
table_5_id PK
table_1_id FK
table_2_id FK
table_3_id FK


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 06, 2005 4:05 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Yes, and? If that represents your relationships and multiplicity, why not?


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