-->
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: Mapping a table to itself (tree-like) and cascade delete
PostPosted: Fri Dec 03, 2010 5:11 pm 
Newbie

Joined: Thu Jan 25, 2007 5:31 am
Posts: 8
Hi,
I'm trying to map a table to itself so that I have a tree-like model. The table looks like this:
Code:
Category (cat_id int, cat_name varchar, cat_parent_id int)

I tried something like this:
Code:
    <many-to-one class="Category" column="cat_parent_id" name="parent" cascade="all" />
    <set name="children" cascade="all" inverse="true">
        <key column="cat_id" />
        <one-to-many class="Category" />
    </set>

and I have this in the DB:
Code:
cat_id  |  cat_name  |  cat_parent_id
--------+------------+---------------
    1   |     c1     |
    2   |     c2     |      1   

when I delete the first category its child doesn't get deleted.
So is what I'm trying to do possible?
I thought this was a common problem but I actually couldn't find anything in the documentation or the forums.

10x


Top
 Profile  
 
 Post subject: [Solve] Mapping a table to itself (tree-like) and cascade de
PostPosted: Sun Dec 05, 2010 1:48 pm 
Newbie

Joined: Thu Jan 25, 2007 5:31 am
Posts: 8
Solved. The mapping was incorrect. This is the correct mapping:
Code:
<many-to-one class="Category" column="cat_parent_id" name="parent" cascade="all" />
<set name="children" cascade="all" inverse="true">
   <key column="parent" />
   <one-to-many class="Category" />
</set>


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.