-->
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: one-to-one to the same class twice ?
PostPosted: Mon Mar 06, 2006 9:45 pm 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
Hibernate version: 2.17

Hi,
I would like to know what's the common practice in handling this requirement: I need to associate the same class twice with one-to-one relationship.

For example, I have class 'File', which has two properties: submitter and lockedBy, both points to a class User.

Mapping documents:

<class name="File" ...>
......
<one-to-one name="submitter" column=".." class="User"/>
<one-to-one name="lockedBy" column=".." class="User"/>
</class>


I do not think we can do this right ?

thanks in advance for your help !

lixin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 06, 2006 9:56 pm 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
correction: it should be two <many-to-one> relationship, not one-to-one.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 12:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Sure you can do that with 2 many-to-ones:
Code:
<class name="File" ...>
    ...
    <many-to-one name="submitter" column="SUBMITTER" class="User"/>
    <many-to-one name="lockedBy" column="LOCKED_BY" class="User"/>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 5:39 am 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
Thank Steve. It is that simple !

one question, this only works with many-to-one, not many-to-many, not one-to-many right ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 9:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
You can do it with any multiplicity *other than one-to-one*. It does not make sense for one-to-one...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 6:25 pm 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
thank you very much !


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.