-->
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.  [ 4 posts ] 
Author Message
 Post subject: Recursive self-join to arbitray depth?
PostPosted: Mon Aug 29, 2005 1:29 am 
Newbie

Joined: Mon Aug 29, 2005 1:14 am
Posts: 10
I have a table that does a self-join to establish parentage to an arbitary depth:

create table cats (
id int not null primary,
parent_id null refernces cats( id ),
name varchar(255)
)

Child rows refernce their (single) parents in the parent_id column:
insert into cats ( 1, null, 'Parent Cat 1' ) ;
insert into cats ( 2, 1, 'Child of Parent Cat 1' ) ;
insert into cats ( 3, 2, 'Child of Child Cat 2' ) ;

With my current hibernate mapping, children are fetched when their parent cat is fetched, but children's children are not.

Is it possible in hibernate to get the children's children fetched?


Hibernate version: 3.0.5

Hibernate mapping:

The pertinent parts of my mapping are:
<class
name="Cat"
table="cat"
>
<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="null"
>


<set
name="children"
table="cat"
>

<key
column="parent_id"
>
</key>

<one-to-many
class="Cat"
/>
</class>


Top
 Profile  
 
 Post subject: Nevermind
PostPosted: Mon Aug 29, 2005 6:40 pm 
Newbie

Joined: Mon Aug 29, 2005 1:14 am
Posts: 10
My bad.

Hibernate does this by default.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 5:20 am 
Newbie

Joined: Wed Aug 03, 2005 1:08 am
Posts: 8
Location: aa
Hi
i have tried your case , and it is working fine on hibernate 3.0
Below is mapping file
<hibernate-mapping package="com">

<class name="com.Data" table="Data" >
<cache usage="read-write" />
<id name="id" column="Id" type="integer">
<generator class="assigned"/>
</id>


<property name="name" column="name" type="string" />

<set name="children" table="Data" cascade="all" >

<key column="parentId" >
</key>

<one-to-many class="Data" />
</set>
</class>

</hibernate-mapping>

_________________
aaa


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 6:08 am 
Newbie

Joined: Mon Aug 29, 2005 1:14 am
Posts: 10
Yup, to my chagrin I found that it works this way by default.

Thanks for taking the time to check it for me, though, I do appreciate that.


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