Hibernate Books

All times are UTC - 5 hours [ DST ]

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: cascade=all behaves like cascade=all,delete-orphan
PostPosted: Sun May 27, 2012 4:22 am 

Joined: Sat Sep 13, 2008 9:45 am
Posts: 4
Hibernate version:3.6.2 final
Personal Oracle Database 11g Release - Production

The relationship is like 1 organization can have multiple volunteers. However 1 volunteer may or may not be linked to an organization.
class Organization{
    private Set<Volunteer> volSets = new HashSet<Volunteer>();
  //other properties

class Volunteer{
   private Organization org;
  //other properties


      <set name="volSets" cascade="all" inverse="true" lazy="false" >
         <key column="org_id" not-null="true" />
         <one-to-many class="com.spring.model.Volunteer" />


<many-to-one name="org" column="org_id" cascade = "none"
         class="com.spring.model.Organization"  />

Ok, lets say there is 1 volunteer linked with this organization.
Then if we delink this volunteer from the organization and then call the delete on the organization, shouldn't it just leave an orphan volunteer?
It instead deletes the volunteer as well.

                        org = orgService.getOrganization(org.getId());
         vol = (Volunteer) org.getVolSets().iterator().next();

This generates the following SQL:

Hibernate: delete from volunteer where vol_id=? and version=?
Hibernate: delete from organization where org_id=? and version=?

I think that's incorrect.Could you please suggest?

To living life on the edge!!! I blog my experiences @http://anirbanchowdhury.wordpress.com/

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

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.