Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 78451 invoked from network); 14 Nov 2009 08:38:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Nov 2009 08:38:45 -0000 Received: (qmail 10790 invoked by uid 500); 14 Nov 2009 08:38:45 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 10746 invoked by uid 500); 14 Nov 2009 08:38:44 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 10734 invoked by uid 99); 14 Nov 2009 08:38:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 14 Nov 2009 08:38:43 +0000 X-ASF-Spam-Status: No, hits=1.4 required=10.0 tests=FORGED_YAHOO_RCVD,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lists+1214986160035-208411@n2.nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 14 Nov 2009 08:38:34 +0000 Received: from tervel.nabble.com ([192.168.236.150]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1N9E97-00054X-E4 for users@openjpa.apache.org; Sat, 14 Nov 2009 00:38:13 -0800 Date: Sat, 14 Nov 2009 00:38:13 -0800 (PST) From: Nikhil Patwardhan To: users@openjpa.apache.org Message-ID: <1258187893429-4003522.post@n2.nabble.com> Subject: Detached entities, version attribute and optimistic concurrency control MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: Nikhil Patwardhan X-Virus-Checked: Checked by ClamAV on apache.org 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.