-->
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: Problem with mapping a collection.
PostPosted: Thu Mar 22, 2007 10:04 am 
Newbie

Joined: Tue Mar 20, 2007 11:48 am
Posts: 11
Hi,

I'm new to hibernate and got stuck with a problem. I got an Item class which holds a list of rents. The problem is that rents can be removed, but this change isn't visible in the database of course when updating the Item object. How can I implement such a thing in a good way?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 11:05 am 
Newbie

Joined: Tue Aug 01, 2006 4:17 am
Posts: 8
In your mapping put cascade="all" or cascade="all-delete-orphan"

Code:
<set name="rents" cascade="all-delete-orphan">
            <key column="ITEM_ID" not-null="true" />
            <one-to-many class="RENT" />
</set>


in your java

Code:
Transaction tx = session.beginTransaction();
Item item = (Item)session.load(Item.class,new Long(YOUR_ID_HERE))
Rent rent= item.getRents().get(1);
rents.remove(rent);
tx.commit();


that should do it.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 12:36 pm 
Newbie

Joined: Tue Mar 20, 2007 11:48 am
Posts: 11
llright, thanks for the quick answer, I'll look at it tommorow.


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.