You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by David Minor <da...@gmail.com> on 2008/05/16 18:58:48 UTC
Optimistic lock exception behavior I can't explain
I'm seeing an optimistic lock exception with a fix I can't quite
explain. I have a field in entity A which references entity B. If I
set this field in A to the same entity B that entity A currently
references, a merge/flush throws an optimistic lock exception. When I
add an 'if' statement to skip setting the field in A if the B entity's
ID fields are the same as the one A currently references, it works
fine.
The object relationship looks something like this:
ObjectA {
@OneToOne(targetEntity = ObjectB.class, fetch = FetchType.EAGER,
cascade = { CascadeType.MERGE, CascadeType.REFRESH })
@JoinColumn(name = "OBJECTB_UID")
@ForeignKey(name = "FK_OA_OBJECTB", enabled = true)
ObjectB getObjectB()
}
ObjectB is referenced through a foreign key which can be null.
So this fails:
instanceOfA.setObjectB(instanceOfB);
serviceLayer.transactionalMergeMethod(instanceOfA);
with:
"org.apache.openjpa.persistence.OptimisticLockException: Optimistic
locking errors were detected when flushing to the data store. The
following objects may have been concurrently modified in another
transaction" -- ObjectA is listed here
And this runs fine:
if ( instanceOfA.getObjectB() != null &&
instanceOfA.getObjectB().getPk() != instanceOfB.getPk() )
instanceOfA.setObjectB(instanceOfB);
serviceLayer.transactionalMergeMethod(instanceOfA);
In the first case instanceOfA is marked as dirty after setObjectB is called.
--
_____________
David Minor