-->
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: Declaring compoent unique (composite unique key constraint)
PostPosted: Tue Mar 02, 2004 8:24 pm 
Newbie

Joined: Sat Jan 10, 2004 10:06 pm
Posts: 9
Location: Calgary, AB, Canada
I have seen a couple of questions like this go by before, but I believe the answer(2) were incorrect.

In my situation, I have a 'business key', which I define as a component with three properties. This key is NOT the primary key, as we all know that is not good persistent OO design, but it indeed is a unique key, as a 3-tuple.

I would like to specify <component ...... unique="true">, hoping that Hibernate would translate that into a unique composite key constraint, but there is no such option available. Others on this list have suggested putting a unique attribute on each of the component's properties, but will this not merely create three disjoint unique keys? How should we declare a composite business key for non-entity type objects?

Jay


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 9:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Code:
<component ....>
   <property .... >
       <column ... unique-key="ukname"/>
   </property>
   <property .... >
       <column ... unique-key="ukname"/>
   </property>
</component>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 9:44 pm 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
Is component required here ?

Won't a unique index be created on the two columns by virtue of the unique-key as long as the value of unique-key is same. At least II think I am getting the same results without the component tag.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 10:05 pm 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
aaa..h.....I get it. component refers to an external class that have the keys defined in it.


Top
 Profile  
 
 Post subject: Isn't there two interpretations of this element?
PostPosted: Wed Mar 03, 2004 12:23 pm 
Newbie

Joined: Sat Jan 10, 2004 10:06 pm
Posts: 9
Location: Calgary, AB, Canada
Thanks for the reply Gavin. But I am still not clear on this. Using the syntax you suggested below, isn't there TWO interpretations of how to set up constraints? How does Hibernate know from this whether I want two, seperate, disjoint unique key constraints OR whether I want a single composite key containing the first column as the primary and the second column as the secondary key? Of course those are completely different kinds of constraints - I know I can get disjoint keys set up without using a component but I am still not clear on how to get a composite key set up....



gavin wrote:
Code:
<component ....>
   <property .... >
       <column ... unique-key="ukname"/>
   </property>
   <property .... >
       <column ... unique-key="ukname"/>
   </property>
</component>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 1:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If you give the same unique-key name, they will be part of the same unique key.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 1:35 pm 
Newbie

Joined: Sat Jan 10, 2004 10:06 pm
Posts: 9
Location: Calgary, AB, Canada
michael wrote:
If you give the same unique-key name, they will be
part of the same unique key.


DOH!!!!! Ok I get it now... thanks to all for the input.

Jay


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.