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.javaCode:
class Organization{
private Set<Volunteer> volSets = new HashSet<Volunteer>();
//other properties
}
Volunteer.javaCode:
class Volunteer{
private Organization org;
//other properties
}
organization.hbm.xmlCode:
<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.xmlCode:
<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?