openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nikhil Patwardhan <niks_...@yahoo.com>
Subject Detached entities, version attribute and optimistic concurrency control
Date Sat, 14 Nov 2009 08:38:13 GMT

Hi,

I'm new to OpenJPA and I have been trying to create a small prototype
demonstrating how I can use it as a JPA compliant persistence provider in a
J2EE web applications. In one of my use cases, I do the following: 

1) Look up an entity(Class name:Document, for instance) using em.find() in
the service layer. The entity has a version field. 

2) Detach the entity by closing the em.

3) Pass the detached entity to the presentation layer (a JSP) which shows a
screen to update various fields of the entity. The UI also has a field for
the version attribute which is sent back on submit.

4) Submit the data back, create a new Document object, set the fields and
call em.merge(document) inside a transaction.

This code fails in step 4 with the following exception when I try to set the
version attribute on the Document object before calling merge().
---------------------------------------------------------------------------------------------------
org.apache.openjpa.persistence.InvalidStateException: Detected attempt to
modify field "core.persistence.Document.docVer" with value strategy
"restrict".
----------------------------------------------------------------------------------------------------
Am I missing something here? My approach here is to set the version
attribute obtained from the UI on the entity to be merged so that optimistic
concurrency control would come into play to find out 
if the entity has been updated since the last read. If version attribute
cannot be set on an entity, I might have to keep the detached entity
obtained from find() in HttpSession and then use it when the updated data is
submitted. But I'm wondering if keeping entities in session is a good idea,
as it can make the session bloated with entities.

-- 
View this message in context: http://n2.nabble.com/Detached-entities-version-attribute-and-optimistic-concurrency-control-tp4003522p4003522.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message