-->
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: Problem with all-delete-orphan
PostPosted: Fri Jun 19, 2009 10:21 am 
Newbie

Joined: Fri Jun 19, 2009 10:03 am
Posts: 1
should all-delete-orphan work for both unidirectional and bidirectional (one2many association) ? is there any rule for this ..

I am trying to delete a child element using all-delete-orphan.... but getting following exception.. .


INFO: Checking 0 named queries
Hibernate: select dept0_.id as id0_, dept0_.name as name1_0_ from dept dept0_ where dept0_.id=?
Hibernate: select emp0_.deptid as deptid__, emp0_.id as id__, emp0_.id as id0_, emp0_.name as name0_0_, emp0_.deptid as deptid0_0_ from emp emp0_ where emp0_.deptid=?
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
at java.util.HashMap$KeyIterator.next(Unknown Source)
at org.hibernate.collection.AbstractPersistentCollection$IteratorProxy.next(AbstractPersistentCollection.java:357)
at Test.removeUser(Test.java:55)
at Test.main(Test.java:66)

Below is my code :

<hibernate-mapping>
<class name="Employee" table="emp">
<id name="empId" column="id">
<generator class="native"/>
</id>
<property name="empName" column="name"/>
<many-to-one name="deptid" column="deptid"/>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="Dept" table="dept">
<id name="deptId" column="id">
<generator class="native"/>
</id>
<property name="deptName" column="name"/>

<set name="emp" cascade="all-delete-orphan">
<key column="deptid"/>
<one-to-many class="Employee"/>
</set>

</class>
</hibernate-mapping>

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Dept dept=(Dept)session.load(Dept.class,new Integer(1));
Iterator<Employee> emps=((Set)dept.getEmp()).iterator();
while(emps.hasNext()){
Employee emp=emps.next();
if(emp.getEmpName().equals("user")){
dept.getEmp().remove(emp);
}
}
tx.commit();
session.close();


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.