-->
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.  [ 2 posts ] 
Author Message
 Post subject: best way to map this configuration
PostPosted: Sat Feb 28, 2009 6:06 am 
Newbie

Joined: Sat Feb 28, 2009 5:44 am
Posts: 1
Hello,

I have two tables : Message[Message_ID [Pk], Sender_ID[FK], Receiver_ID[FK], and some other fields] and Person[Person_ID[PK] and other fields(no fk)]. Sender_ID and Receiver_ID are FK referencing Person.

The java classes will look like this:
class Message
{
//other fields
Person sender;
Person receiver;
}

class Person
{
//other fields
Set<Message> sentMessages = new HashSet<Message>();
Set<Message> recievedMessages = new HashSet<Message>();

How should I map this configuration?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 28, 2009 10:02 am 
Newbie

Joined: Thu Feb 26, 2009 8:21 pm
Posts: 4
May be u can try this:
Code:
<!-- ... -->
<class name="Message" table="Message">
<!-- id go here -->
<many-to-one name="sender" class="Person" column="Sender_Id" />
<many-to-one name="receiver" class="Person" column="Receiver_Id" />
<!-- other properties -->
</class>
<class name="Person" table="Person">
<!-- id go here -->
<set name="sentMessages">
<key column="Sender_Id" />
<one-to-many class="Message" />
</set>
<set name="receivedMessages">
<key column="Receiver_Id" />
<one-to-many class="Message" />
</set>
</class>


Book: "Hibernate in Action" may also help u a lot.


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