-->
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.  [ 3 posts ] 
Author Message
 Post subject: mapping entity to itself?
PostPosted: Thu Jul 08, 2004 12:29 pm 
Newbie

Joined: Wed Jun 30, 2004 11:00 am
Posts: 7
Is it possible to map an entity to itself with hibernate? I've searched the forums but haven't seen any mention to this.

I have a table MESSAGE (pk MESSAGE_ID). It contains an optional column named PARENT_MESSAGE_ID. I'd like to create relationship off of Message called "messageReplies" which would basically fetch all Messages that have a PARENT_MESSAGE_ID equal to this message's MESSAGE_ID.

It seems hibernate is very strict about pk/fk key names. It is possible to create a relationship like this?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 08, 2004 12:32 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Thats easy:

Code:
<class name="Message">
    <id .../>
    <many-to-one name="parentMessage" column="PARENT_MSG_ID"/>
    <set name="childMessages>
        <key column="PARENT_MSG_ID"/>
        <one-to-many class="Message"/>
    </set>
</class>

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Sorry
PostPosted: Thu Jul 08, 2004 12:59 pm 
Newbie

Joined: Wed Jun 30, 2004 11:00 am
Posts: 7
Yeah, that worked perfectly. I felt like i had the relationhiped previoulsy mapped like that, but something exploded. Could have been related to something else.

Thanks for the quick reply. And sorry again for the noise.


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