Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 73168 invoked from network); 22 Sep 2008 22:47:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Sep 2008 22:47:39 -0000 Received: (qmail 79261 invoked by uid 500); 22 Sep 2008 22:47:36 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 79233 invoked by uid 500); 22 Sep 2008 22:47:36 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 79222 invoked by uid 99); 22 Sep 2008 22:47:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Sep 2008 15:47:36 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of michael.d.dick@gmail.com designates 209.85.198.237 as permitted sender) Received: from [209.85.198.237] (HELO rv-out-0506.google.com) (209.85.198.237) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Sep 2008 22:46:36 +0000 Received: by rv-out-0506.google.com with SMTP id g37so1723209rvb.33 for ; Mon, 22 Sep 2008 15:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type:references; bh=zBoifxLAa9cjBee9LvQnPeXIYdVs4xsTz2gOd/onhd4=; b=PrNxvAPlV8+m5Iqt8wvvlxBSdAbO6S+p4LVcsHwBO1apLaa7SJT2b4cD/Rs4v/t156 ihKBajtr64wP4GjRePMr9H65JALZbBcGI9I5P+j5D8I5FO8K2Km7am1DOPhOWPj1NRxp VLPZK1R2yKpFcPxTXfKgc8/eGbSCn8C/9eJxg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:references; b=Oths0gFMF6aUi1ukPMUgNxMQk6onZeDvHiy+H2JU4h3v14ky45DkYE7+JpI8SCWKWp N9/XHr5ZsVY/3TiT/1ow8Lblz1oe/VIjKUk2C6jYqeduFJObJ4bxC3fH57D3gbZcVHx0 DdeXth+3CcTyCDezo6Eid5WX/vuXbyZjRrzHw= Received: by 10.140.191.14 with SMTP id o14mr2324082rvf.78.1222123619812; Mon, 22 Sep 2008 15:46:59 -0700 (PDT) Received: by 10.141.132.9 with HTTP; Mon, 22 Sep 2008 15:46:59 -0700 (PDT) Message-ID: <72c1350f0809221546y76db776x1ae57edfc0e4b034@mail.gmail.com> Date: Mon, 22 Sep 2008 17:46:59 -0500 From: "Michael Dick" To: dev@openjpa.apache.org Subject: Re: Updates to entities via Lifecycle callback methods In-Reply-To: <89c0c52c0809221354i50247207ic78645faa8f15980@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_391_28023001.1222123619817" References: <89c0c52c0809221354i50247207ic78645faa8f15980@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_391_28023001.1222123619817 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I think there may be valid use cases where updating *the* entity in a PreUpdate callback method is valid. One example might be implementing a wiki. On each update of a page you may want to update the version and update a lastUpdatedBy attribute with the userid that made the update. The PreUpdate callback is a fairly logical place to make such a change. Absent a compelling reason why an application can't update the entity in a callback method I'm inclined to view this as a good improvement. -mike On Mon, Sep 22, 2008 at 3:54 PM, Kevin Sutter wrote: > Hi, > I've been talking to MikeD about this and I thought I should get some input > from other experts... > > In the EntityListener methods, we can pass an instance of the entity to the > method invocation. Is it valid for these methods to update this entity > instance? The JPA spec and Pro EJB3 book don't indicate one way or the > other. And, all of the examples cited just show read only usage of the > entities passed in. The spec is clear that you can't utilize EntityManager > and Query operations, but it doesn't qualify what you can or can not do to > the entity itself. > > The specific scenario that I am experiencing is a @PreUpdate method is > calling a setter method on one of it's attributes. OpenJPA is getting a > little confused with this since this processing is updating the @Version > field (when it really doesn't need to). So, the commit rolls back due to > inconsistent @Version values. And, due to this update-within-an-update, we > end up calling the @PostUpdate listener twice for the same entity instance. > Like I said, we get kind of confused. > > Before I open a JIRA to address this problem, I'm wondering whether anybody > is reading the spec differently and this should not be allowed. (BTW, I'm > hearing that Hibernate can process this okay, but I have not been able to > confirm this.) > > Comments and discussion welcome. > > Thanks, > Kevin > ------=_Part_391_28023001.1222123619817--