Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 48601 invoked from network); 9 Jul 2009 15:40:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 9 Jul 2009 15:40:28 -0000 Received: (qmail 29696 invoked by uid 500); 9 Jul 2009 15:40:37 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 29631 invoked by uid 500); 9 Jul 2009 15:40:37 -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 29608 invoked by uid 99); 9 Jul 2009 15:40:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Jul 2009 15:40:37 +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, 09 Jul 2009 15:40:35 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id C59D029A0011 for ; Thu, 9 Jul 2009 08:40:14 -0700 (PDT) Message-ID: <824866702.1247154014794.JavaMail.jira@brutus> Date: Thu, 9 Jul 2009 08:40:14 -0700 (PDT) From: "Michael Dick (JIRA)" To: dev@openjpa.apache.org Subject: [jira] Commented: (OPENJPA-327) EntityListener that modify property value of a entity, causes invalid state exception In-Reply-To: <18651899.1187816671078.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-327?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12729300#action_12729300 ] Michael Dick commented on OPENJPA-327: -------------------------------------- Hi B.J. I'm going to reattach your patches to OPENJPA-732 and apply the fix under that JIRA. It's a shame that we didn't mark 732 as a duplicate of this one when we first fixed it but I don't want to have two separate issues which essentially fix the same problem (just different releases). It'll be a little easier to just track the single issue (at least for me). Thanks for the patches though! > EntityListener that modify property value of a entity, causes invalid state exception > ------------------------------------------------------------------------------------- > > Key: OPENJPA-327 > URL: https://issues.apache.org/jira/browse/OPENJPA-327 > Project: OpenJPA > Issue Type: Bug > Components: jpa > Affects Versions: 1.0.0 > Environment: windows xp, jdk 5 > code was build time enhanced > Reporter: Henry Lai > Assignee: Michael Dick > Attachments: OPENJPA327-1.0.patch, OPENJPA327-1.2.patch, ptpissue1.zip > > > entitylistener callback that modifies property value of the entity throws exception > The following test code produces the following exception > <1.0.0-SNAPSHOT-SNAPSHOT fatal user error> org.apache.openjpa.persistence.InvalidStateException: Attempt to set column "T1ENTITY.VER_ID" to two different values: (class java.lang.Integer)"2", (class java.lang.Integer)"3" This can occur when you fail to set both sides of a two-sided relation between objects, or when you map different fields to the same column, but you do not keep the values of these fields in synch. > at org.apache.openjpa.jdbc.sql.PrimaryRow.setObject(PrimaryRow.java:338) > at org.apache.openjpa.jdbc.sql.RowImpl.setObject(RowImpl.java:505) > /** > * for entity with version field, and if the lifecycle listener such as > * pre-persist, post-persist handler modifies the entity > * then when flush is invoke, results in optimistic lock exception > * > * this test failes in openjpa 0.9.6 > * this test failes in openjpa 0.9.7 > * this test failes in openjpa 1.0.0 > * > * This test case will past with either of following changes > * 1) comment out em.flush(); > * 2) uncomment in the orm.xml file > * > */ > public void testMultipleInsertWithEntityListener(){ > > PersistenceProviderImpl openJPA = new PersistenceProviderImpl(); > EntityManagerFactory factory = > openJPA.createEntityManagerFactory("test", "ptp/test/issue1/persistence.xml", > System.getProperties() ); > > EntityManager em = factory.createEntityManager(); > em.getTransaction().begin(); > T1Entity e1 = new T1Entity(); > T1Entity e2 = new T1Entity(); > e1.setName("Mickey"); > e2.setName("Goofy"); > > em.persist(e1); > em.flush(); // works if this line is commented out > > em.persist(e2); > em.getTransaction().commit(); > em.close(); > } > package ptp.test.issue1; > import java.sql.Timestamp; > public class T1EntityListener { > static int count; > int instNum; > public T1EntityListener() { > instNum = count++; > System.out.println("T1EntityListener=" + this + ", instance=" + instNum ); > } > public void preUpdate(Object entity) { > audit( "preUpdate", entity); > } > public void postUpdate(Object entity) { > audit( "postUpdate", entity); > } > public void prePersist(Object entity) { > audit( "prePersist", entity); > } > public void postPersist(Object entity) { > audit( "postPersist", entity); > } > public void audit(String eventName, Object entity) { > if (entity instanceof IAudit) { > IAudit auditEntity = (IAudit) entity; > System.out.println("****T1EntityListener inst=" + instNum + ", event=" + eventName + ", entity=" + auditEntity + ", ver=" + auditEntity.getVerId()); > try { > auditEntity.setModifyDateTime(createTimeStamp()); > } catch (Exception e) { > throw new RuntimeException(e); > } > } > } > > private Timestamp createTimeStamp() { > return new Timestamp(System.currentTimeMillis()); > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.