openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Minor" <>
Subject Optimistic lock exception behavior I can't explain
Date Fri, 16 May 2008 16:58:48 GMT
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

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:


"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() )

In the first case instanceOfA is marked as dirty after setObjectB is called.

David Minor

View raw message