• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Problem with all-delete-orphan

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
 
author and cow tipper
Posts: 5001
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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=?



Throw that code right into you SQL tool and send it directly to the database with a valid deptid and see what happens. I want to see that the error isn't at the database level, and is in fact, a problem with the Hibernate mapping. Is that possible? Which database are you using?

-Cameron McKenzie
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"super sonic"

Please click on the My Profile link above and change your display name to meet the JavaRanch Naming Policy of using your real first and real last names.

Thanks

Mark
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"ConcurrentModificationException "

Doesn't that occur when you have updated an object and before that update has been commited you try and delete that object?

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic