-->
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.  [ 4 posts ] 
Author Message
 Post subject: Using cascading update()
PostPosted: Fri Oct 31, 2003 4:03 am 
Newbie

Joined: Tue Oct 28, 2003 2:20 am
Posts: 9
Location: Bangalore, India
Hi,

I have Department-has-Employee(s) relationship. I want to update the department like this

- update Employee record if the id in transient object is set
- insert a new Employee record for Department if id is not set
- delete all Employee records that are in the database but not in the getEmployees() collection of Department.

The first 2 cases work as mentioned in 8.4. There is not mention of delete of child records in 8.4. Can the third case be made to work with Hibernate? If yes, what do I need to do?

Thank you.

Ram.[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 4:23 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If you want that any orphan employee be deleted, use the cascade=""all-delete-ophan"

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 5:12 am 
Newbie

Joined: Tue Oct 28, 2003 2:20 am
Posts: 9
Location: Bangalore, India
Hi,

I turned on cascade="all-delete-orphan" and it now throws an exception
Quote:
You may not dereference a collection with cascade="all-delete-orphan"


I have not changed anything else except the cascade for Department

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
   <class name="com.infosys.j2ee.cmptest.model.Department" table="DepartmentEJBTable">
   <id name="primaryKey">
      <generator class="sequence">
         <param name="sequence">test2_seq</param>
      </generator>
   </id>
   <property name="name">
      <column name="NAME"/>
   </property>
   <property name="location">
      <column name="LOCATION"/>
   </property>
   <bag name="employees" inverse="true" outer-join="true" cascade="all-delete-orphan">
      <key column="departmentid"/>
      <one-to-many class="com.infosys.j2ee.cmptest.model.Employee"/>
   </bag>
   
   </class>

   <class name="com.infosys.j2ee.cmptest.model.Employee" table="EmployeeEJBTable">
   <id name="primaryKey">
      <generator class="sequence">
         <param name="sequence">test2_seq</param>
      </generator>
   </id>
   <property name="name">
      <column name="NAME"/>
   </property>
   <property name="employeeNumber">
      <column name="EMPLOYEENUMBER"/>
   </property>
   <property name="hireDate">
      <column name="HIREDATE"/>
   </property>
   <property name="salary">
      <column name="SALARY"/>
   </property>   
   <many-to-one name="department" class="com.infosys.j2ee.cmptest.model.Department" column="departmentid" cascade="all"/>
   </class>      
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 5:28 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://forum.hibernate.org/old/918689.html

When using all-delete-orphan, you're supposed to keep the actual hibernate wrapper collection, to let hibernate know which objects are really orphans

_________________
Emmanuel


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