-->
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: composite / natural key
PostPosted: Wed Mar 01, 2006 8:58 am 
Newbie

Joined: Wed Mar 01, 2006 4:14 am
Posts: 16
I have a key (Long) with autonumbering in a table
but there is a combination of properties that is unique
(String username + Long referenceToOtherTable + Date start + Date end)

how can I do this withoud having a Component like this

<id name="id" .../>
<component unique="true" ...>
<property name="username " .../>
<property name="referenceToOtherTable " .../>
<property name="start " .../>
<property name="end" .../>
</component>

because then I need another class for this component that has no specific meaning, or is this the only way (component + extra class)?


Top
 Profile  
 
 Post subject: just map
PostPosted: Wed Mar 01, 2006 12:01 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Just map them as properties of your class, there is no need to declare component unless you want to.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 3:27 am 
Newbie

Joined: Wed Mar 01, 2006 4:14 am
Posts: 16
I need to have that combination of properties unique
if I put unique in each of the properties; each of them are in their own right unique and that's not what I want


Top
 Profile  
 
 Post subject: DB
PostPosted: Thu Mar 02, 2006 11:29 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Just define that unique constraint at DB level, and you could check it at class level as well if you want.
Generate DB schema yourself as you need it, do not trust Hibernate to do it.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 5:36 am 
Newbie

Joined: Wed Mar 01, 2006 4:14 am
Posts: 16
ok, defining the constraint at database level is not my job but what do you mean by checking it at class level then


Top
 Profile  
 
 Post subject: meaning
PostPosted: Fri Mar 03, 2006 11:24 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
I mean validation on save or update.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.