From dev-return-11633-apmail-openjpa-dev-archive=openjpa.apache.org@openjpa.apache.org Thu Apr 30 07:06:59 2009 Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 61497 invoked from network); 30 Apr 2009 07:06:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 30 Apr 2009 07:06:58 -0000 Received: (qmail 61882 invoked by uid 500); 30 Apr 2009 07:06:58 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 61853 invoked by uid 500); 30 Apr 2009 07:06:58 -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 61843 invoked by uid 99); 30 Apr 2009 07:06:58 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Apr 2009 07:06:58 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Apr 2009 07:06:51 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 2F9CD234C04B for ; Thu, 30 Apr 2009 00:06:31 -0700 (PDT) Message-ID: <962857675.1241075191193.JavaMail.jira@brutus> Date: Thu, 30 Apr 2009 00:06:31 -0700 (PDT) From: "Julien Kronegg (JIRA)" To: dev@openjpa.apache.org Subject: [jira] Updated: (OPENJPA-1018) @PreUpdate raised for new entities annotated with @EntityListeners In-Reply-To: <1933731192.1238683032915.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/OPENJPA-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Julien Kronegg updated OPENJPA-1018: ------------------------------------ Environment: http://fisheye6.atlassian.com/browse/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?r=761031 IBM J9 VM 1.5.0, deployed as standalone Java application or as Websphere 6.1 WAR was:http://fisheye6.atlassian.com/browse/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?r=761031 > @PreUpdate raised for new entities annotated with @EntityListeners > ------------------------------------------------------------------ > > Key: OPENJPA-1018 > URL: https://issues.apache.org/jira/browse/OPENJPA-1018 > Project: OpenJPA > Issue Type: Bug > Components: kernel > Affects Versions: 1.2.0, 1.2.1, 1.3.0, 2.0.0 > Environment: http://fisheye6.atlassian.com/browse/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?r=761031 > IBM J9 VM 1.5.0, deployed as standalone Java application or as Websphere 6.1 WAR > Reporter: Julien Kronegg > Original Estimate: 4h > Remaining Estimate: 4h > > Given the following entity: > @Entity > @EntityListeners({Auditing.class}) > @Table(...) > public class A { > ... > } > and the following Auditing class: > public class Auditing { > @PreUpdate > public void preUpdate(Object entity) { // the provided object is supposed to be a PersistenceCapable > ... > } > } > When using runtime enhancement, the PreUpdate event is raised and preUpdate(Object) is called when persisting a new entity: the call is not expected as the entity is not yet persisted (moreover, the entity passed in parameter is not an instance of PersistenceCapable). > This is due to StateManagerImpl.preFlush() lifecycle event firing conditions: > // BEFORE_PERSIST is handled during Broker.persist and Broker.attach > if (isDeleted()) > fireLifecycleEvent(LifecycleEvent.BEFORE_DELETE); > else if (!(isNew() && !isFlushed()) > && (ImplHelper.getUpdateFields(this) != null)) > fireLifecycleEvent(LifecycleEvent.BEFORE_UPDATE); > When processing a PNewState, the condition for BEFORE_UPDATE event becomes simply: isFlushed(), i.e. the BEFORE_UPDATE event is raised for a new Entity! (stuff below is supposed to be a boolean table, sorry for the loosy presentation): > isNew > true.....false > isFlushed.......true......fire.......fire > false......X.........fire > where X means "do nothing" and fire means "fire the BEFORE_UPDATE event". > The correct full condition would include a condition to prevent raising BEFORE_UPDATE for new entities: > isNew > true.....false > isFlushed.......true........X.........fire > false......X.........fire > where X means "do nothing" and fire means "fire the BEFORE_UPDATE event", which finally gives: > else if (!isNew() && (ImplHelper.getUpdateFields(this) != null)) -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.