-->
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: Object related to itself, how to map that
PostPosted: Thu Aug 26, 2004 6:48 pm 
Newbie

Joined: Thu Aug 26, 2004 6:29 pm
Posts: 1
I have an "Operation" object which needs to have a list of other "Operation" objects related.
Course on the DB i need a relation (some like "LinkedOperations") table with, say id1 and id2 columns, but not sure how to map that on Hibernate (if possible).

As the java object it's easy to think on an Operation object with a List of Operations but i'm confused about the mappings

Should i create a LinkedOperations object (just with the id's) and make a many-to-many relation with the Operation object, then on runtime read the list of linked object ids and manually? load each one when needed or is there any way hibernate can load the related objetcs automatically ?.

Any help appreciated

My ideas are confused and my english does not help, so.... sorry ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 2:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
of course it is possible, it is exactly the same as if there were 2 differents tables... nothing particular more to do.


Table:
id
colA
idFather

Pojo:
private long id;
private string a;
private Pojo father;
private Set children;

Mapping:
<id.../>
<name="a" ..../>
<many-to-one name="father" column="idFather">
<set name="children">
<key column="idFather">
<one-to-many class="theSame"/>
</set>

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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.