openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From areider <>
Subject Delete OptimisticLock exception, when entity appears 2x in cascade graph
Date Tue, 11 Oct 2011 22:46:46 GMT
I'm using 1.2.3_Snapshot (that comes with IBM RAD 7.5). 

I'm having an issue with remove operation receiving an Optimistic Lock

My domain includes a structure which would be similar to a Department and
Employees. Thus:
All employees own a relationship to a Department
Employees optionally own a relationship to another Employee in the same

class Department {
@OneToMany(mappedBy="department", cascade=CascadeType.ALL)
List<Employee> employees;

class Employee {

Department department;

Employee manager;

List<Employee> employees;

public boolean equals(){
// entities are equal if their primary keys are equal
public hashCode(){
// entities with same primary key have the same hashCode

So an Employee has a foreign key (FK) to a Department as well as
(optionally) another Employee.

The FK to department has referential integrity (RI) and is not nullable. 
The FK to another Employee has RI, and is not nullable.
I'm not at liberty to change this structure or the RI.

Consider the following instance of a department

So we have an entity structure where an entity may appear more than once in
the graph of objects reachable by a cascaded delete. Is this supported?
When I try to removing Dept, I get an OptimisticLock exception that Joe is
currently being modified in another transaction. Apparently it tries to
remove Joe twice (at least I see that @PreRemove and @PostRemove are each
entered for Joe twice). 

Shouldn't it be avoiding the 2nd remove of Joe since it is equal() to the
1st instance found?

(At some point, possibly before implementing equals()/hashcode, i was
getting an error from DB2 indicating an RI was violated trying to delete
JoesBoss before Joe (since JoesBoss happens to be before Joe in the
department list), so perhaps the RI (delete sequence) issue is orthogonal to
the lock issue).

Is this a known problem and/or has it been fixed in a later release?

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message