-->
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.  [ 1 post ] 
Author Message
 Post subject: cascade=all behaves like cascade=all,delete-orphan
PostPosted: Sun May 27, 2012 4:22 am 
Newbie

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

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

Volunteer.java
Code:
class Volunteer{
   private Organization org;
  //other properties
}


organization.hbm.xml
Code:

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

volunteer.hbm.xml

Code:
<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.

Code:
   
                        org = orgService.getOrganization(org.getId());
         vol = (Volunteer) org.getVolSets().iterator().next();
         org.getVolSets().remove(vol);
         vol.setOrg(null);
         orgService.deleteOrganization(org.getId());


This generates the following SQL:

Code:
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/


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