Hi paulvitic,
The defined JPA version field should only be updated for those Entities that
have been updated.  If the Provision entities are not being updated in your
scenario, then the version field should not be updated.  From section 3.4.2
of the JPA 1.0 spec:

"The version attribute is updated by the persistence provider runtime when
the object is written to the
database. All non-relationship fields and properties and all relationships
owned by the entity are
included in version checks."

Are you sure that the Optimistic Lock Exception is due to the Provision
entity's version field, and not the version field of the AssetAttributeValue
entity?

I looked through some of our JIRAs and found this one (
https://issues.apache.org/jira/browse/OPENJPA-843), but this seems to
describe the inverse of your situation.  What level of OpenJPA are you
using?  This JIRA has been resolved for quite some time in the 1.2.x, 1.3.x,
and 2.0.x branches, but it's possible you are running with an older version.

The other thing you can do to help isolate the problem is to turn on some
tracing.  Even a simple SQL trace would show what's being updated in the
Provision entities other than the version.  If it's only the version that is
getting updated, then I would say there's a problem that needs to be
resolved.

<property name="openjpa.Log" value="SQL=TRACE"/>

Good luck,
Kevin

On Wed, Dec 15, 2010 at 9:15 AM, paulvitic <[email protected]> wrote:

>
> We have an AssetAttributeValue entity which gets frequent updates (1.5
> updates per second). AssetAttributeValue has a AssetAttribute property.
> Relationship between AssetAttributeValue and AssetAttribute is
> ManyToOne(fetch = FetchType.LAZY). AssetAttribute has a Provision property.
> Relationship between AssetAttribute and Provision is ManyToMany.
>
> Updates on AssetAttributeValue updates version field of Provision. We are
> not completely sure about this but version update of Provision seems to
> happen when an AssetAttribute instance is related to more than one
> Provision.
>
> Normally this would not pose a problem but in our application multiple
> threads update AssetAttributeValue and because of version difference of
> Provision we get optimistic lock exception.
>
> Can anyone shed a light on this behavior. In such a entity model when
> should
> we expect the Provision number to be updated? Can we prevent this update?
>
> Any other advise would be welcome.
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/version-field-updated-indirectly-tp5838027p5838027.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Reply via email to