-->
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: delete orphans on Set failed
PostPosted: Mon Jul 18, 2005 11:54 am 
Newbie

Joined: Thu Jun 24, 2004 4:06 am
Posts: 9
First i want to precised that i have read all possible posts on this problem in this forum but i didn't find any fix.

My settings:
Hibernate version: 3.0.5 JDK 1.5.0_03
Name and version of the database: hsqldb
mapping
Code:
<class name="BookingBO" table="booking" proxy="BookingBO">
   <id name="bkgnum" type="string">
      <generator class="assigned"/>
   </id>
   <set name="rooms" lazy="false" inverse="true" cascade="all-delete-orphan">
      <key column="bkgnum"/>
      <one-to-many class="RoomStayBO" />
   </set>
</class>

Code:
<class name="RoomStayBO" table="roomstay" proxy="RoomStayBO">
   <id name="roomstayid" type="integer">
      <generator class="identity"/>
   </id>
   <property name="bkgnum" type="string" />
</class>

The generated SQL (show_sql=true):
I have an object "booking" with two objects "roomstay" in a set.
i try to delete one of this roomstay and update another field in booking object.
Because user is using a swing UI to make changes, roomstay displayed are "cloned" to allow user to cancel it's change using a cancel button on dialog:
->a mainpanel is displaying booking with a list of room stays
->user can select a roomstay to edit it (in such case, room stay is cloned)
->if user validate his change, room stay edited replace old one in Booking object Set.
->When user validate change on booking, hibernate is called with booking to update. The Set in booking object to update is not a new one:
Code:
booking1.getRooms().clear();
List<RoomStayBO> roomStays = this.roomStayPN.getRoomStays();
booking1.getRooms().addAll(roomStays);;

The generated SQL (show_sql=true):
Hibernate: update booking set leadpaxid=?, (...)
Hibernate: update roomstay set bkgnum=?, (...)

The orphan roomstay is neither updated, nor deleted. In debugging mode, i notice that getOrphans() from PersistentSet is called but never returns a collection containing my deleted object.

Any idea?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 12:13 pm 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Try with inverse="false" for rooms:
Code:
<set name="rooms" lazy="false" inverse="false" cascade="all-delete-orphan">
      <key column="bkgnum"/>
      <one-to-many class="RoomStayBO" />
</set>


As rule inverse="true" is used for Bidirectional Parent-Child mapping. But in your RoomStayBO you do not have a reference to the parent, so you don't need inverse="true"

_________________
Leonid Shlyapnikov


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 12:17 pm 
Newbie

Joined: Thu Jun 24, 2004 4:06 am
Posts: 9
thanks shl for this quick reply :)
But I have fixed the problem: somewhere in my code i create a new HashSet and that's why orphans were not deleted.


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.