Hibernate version:
2.1.7c
Mapping documents:
class A:
Code:
...
<set name="myBs"
lazy="true"
inverse="true"
cascade="delete"
sort="unsorted"
order-by="value"
>
<key column="idA">
</key>
<one-to-many class="test.B"/>
</set>
...
class b:
Code:
...
<many-to-one
name="myA"
class="test.A"
cascade="none"
outer-join="true"
update="true"
insert="true"
access="property"
>
<column name="idA"/>
</many-to-one>
...
Code between sessionFactory.openSession() and session.close():Code:
session.delete(A);
In the Lifecylce delete method of class B (simplified):
Code:
getMyA.getMyBs.remove(this);
Full stack trace of any exception that occurs:
java.util.ConcurrentModificationException
....
Name and version of the database you are using:
MySQL 4.1.7
The generated SQL (show_sql=true):
-
Debug level Hibernate log excerpt:
-
Hello!
I have two classes A and B. A has a set of Bs (1:n) and the relationship is bidirectional. If A is deleted, all Bs should be deleted. I set the cascade to "delete" in class A. In class B I implemented the Lifecycle interface to update the java model when removing an instance of B (in this case, the set in class A must be updated).
When I delete an instance of B, everything is fine. However, I'm getting a ConcurrentModificationException when I delete an instance of A. Apparently I'm removing the instance of B from the set of A, while Hibernate is iterating this set. So how can I ensure a proper update of the java model? Must I do this outside of the Lifecycle methods?
Thanks!!
Jonas