From dev-return-6829-apmail-openjpa-dev-archive=openjpa.apache.org@openjpa.apache.org Sun Nov 18 01:15:27 2007 Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 72356 invoked from network); 18 Nov 2007 01:15:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Nov 2007 01:15:27 -0000 Received: (qmail 57270 invoked by uid 500); 18 Nov 2007 01:15:14 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 57234 invoked by uid 500); 18 Nov 2007 01:15:14 -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 57225 invoked by uid 99); 18 Nov 2007 01:15:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 17 Nov 2007 17:15:14 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of plinskey@gmail.com designates 64.233.166.176 as permitted sender) Received: from [64.233.166.176] (HELO py-out-1112.google.com) (64.233.166.176) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Nov 2007 01:15:04 +0000 Received: by py-out-1112.google.com with SMTP id f47so5116161pye for ; Sat, 17 Nov 2007 17:14:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=+zMvTUhOW5hQJUIdlpDHyMh9SHv00VBOEx+Cgf0eCz8=; b=KCTzvl6GhvjWPuP2kclQNJE6LpLifjkjSPGJdvlaOTBYYBB/bChotXgvw3995i4qGCsOXlxAlxORo+Y03vN0lPJZJroP3cvhhPn2k92B2pFFUSTpfqs+5wrPAUBV2gARTUG09lVGwaepMIwC9HVCJMGEKbFa5x1ntaxc0b2kIz0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=LeNCSOApuK6N0XVOZCwP/XsCSxDcD7KykFb5FC+Q6C//SUpqYcOREPIy8xmVNmdaAOzq2EQ6ONupn2po+DMP72Gr5SBP1LZRYSJuHuJsJ20hI/SG/jivXUQxKZuQOb8gWY+7eWUzc18PQs8UrhTUFbKFVfDOMos6rIzhU3DtM9I= Received: by 10.142.52.9 with SMTP id z9mr867208wfz.1195348495383; Sat, 17 Nov 2007 17:14:55 -0800 (PST) Received: by 10.143.165.19 with HTTP; Sat, 17 Nov 2007 17:14:55 -0800 (PST) Message-ID: <7262f25e0711171714t2c9e045bha2731a099d805bf0@mail.gmail.com> Date: Sat, 17 Nov 2007 17:14:55 -0800 From: "Patrick Linskey" To: dev@openjpa.apache.org Subject: Re: @PostPersist woes In-Reply-To: <67CB98BE-D2DB-4DD9-9BEB-EA40417331F0@pobox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <535E699A-DC3D-46AE-AF17-7652D0C59ABD@pobox.com> <3992B07C0590B548BB294D31768A1DA2A1287E@repbex01.amer.bea.com> <2730F200-F5BB-4BF9-B84E-99B3A129574F@pobox.com> <7B72614E-A76C-4105-AE4F-A6DC4DBC7462@SUN.com> <7262f25e0711171649t1143c89cj2b55b6df92afeee7@mail.gmail.com> <67CB98BE-D2DB-4DD9-9BEB-EA40417331F0@pobox.com> X-Virus-Checked: Checked by ClamAV on apache.org I'm just pointing out that there is more to your situation than your description to Craig. -Patrick On Nov 17, 2007 5:12 PM, Geir Magnusson Jr. wrote: > > On Nov 17, 2007, at 7:49 PM, Patrick Linskey wrote: > > > I think that there was a bit more to it... I think that you were also > > trying to do something that required getting the OID during a > > @PostPersist, right? > > I thought I could do that. The spec seems to say that. > > A needs it's own PK. B needs it's own PK. But B doesn't need to > know A's PK for the action it takes in the @PostPersist method. > > > > > > > > > -Patrick > > > > On Nov 17, 2007 12:26 PM, Geir Magnusson Jr. wrote: > >> > >> On Nov 16, 2007, at 3:00 PM, Craig L Russell wrote: > >> > >>> Hi Geir, > >>> > >>> It still isn't clear to me what you are trying to accomplish. Would > >>> it be possible for you to describe what the goal is? (I might have > >>> missed the key idea in earlier posts...) > >>> > >> > >> Persist an object graph in which object A that has a auto-gen PK > >> and a > >> reference to object B, such that object B has a PK and a reference to > >> object A via a FK in table B. > >> > >> I found a workaround for now. I need to see if Hibernate can do > >> this. I think it can. I realize that depending on that isn't > >> portable, but it sure was convenient. > >> > >> geir > >> > >> > >> > >>> Craig > >>> > >>> On Nov 15, 2007, at 1:59 PM, Geir Magnusson Jr. wrote: > >>> > >>>> > >>>> On Nov 15, 2007, at 4:41 PM, Geir Magnusson Jr. wrote: > >>>> > >>>>> > >>>>> On Nov 15, 2007, at 4:34 PM, Pinaki Poddar wrote: > >>>>> > >>>>>>> persist() has in it a new, unmanaged entity. > >>>>>> > >>>>>> a) If persist(a) is failing on b, what is the cascade type > >>>>>> specified on > >>>>>> relation a.b? > >>>>> > >>>>> I'm not actually sure that it's failing on b. I guess I can try to > >>>>> figure that out. I just know that when I change things so that I > >>>>> have an unmanaged b, it fails. > >>>> > >>>> So I put some printlns in my @PostPersist routine, and I see that > >>>> for something w/o the reference to an unmanaged entity, I get a > >>>> sequence like this : > >>>> > >>>> [junit-coverage] ###### 1 I'm a class com.joost.model.show.Show > >>>> [junit-coverage] ###### 2 I'm a class com.joost.model.show.Show > >>>> [junit-coverage] 7996 pu TRACE [main] openjpa.jdbc.SQL - >>>> 9777317, conn 7891417> executing prepstmnt 9148991 INSERT INTO > >>>> APP.INVENTORYITEM (CHANGENUMBER, COID, CREATIONDATE, DELETED, > >>>> FIRSTPUBLICATIONDATE, LASTMODIFICATIONDATE, LATESTPUBLICATIONDATE, > >>>> NAME, OKTOPUBLISH, PUBLICID, PUBLISHED, UUID, ITEMTYPE, DAMID, > >>>> OWNERID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) > >>>> [params=(null) null, (null) null, (Timestamp) 2007-11-15 > >>>> 16:51:04.42, (int) 0, (null) null, (Timestamp) 2007-11-15 > >>>> 16:51:04.42, (null) null, (String) a, (int) 0, (null) null, (int) > >>>> 0, (String) 007ddeca-edff-4657-927f-ce77205c28ef, (String) > >>>> VideoShow, (int) 10, (int) 10] > >>>> [junit-coverage] 7997 pu TRACE [main] openjpa.jdbc.SQL - >>>> 9777317, conn 7891417> [1 ms] spent > >>>> [junit-coverage] 7997 pu TRACE [main] openjpa.jdbc.SQL - >>>> 9777317, conn 7891417> executing prepstmnt 13415937 > >>>> VALUES(IDENTITY_VAL_LOCAL()) > >>>> [junit-coverage] 7997 pu TRACE [main] openjpa.jdbc.SQL - >>>> 9777317, conn 7891417> [0 ms] spent > >>>> [junit-coverage] 8004 pu TRACE [main] openjpa.jdbc.SQL - >>>> 9777317, conn 7891417> executing prepstmnt 6406303 INSERT INTO > >>>> APP.VIDEOSHOW (ID, ADSFREE, CODURATION, COFILENAME, > >>>> MAINDESCRIPTION, MAINTITLE, MINAGE, PRODUCTIONYEARS, ISPROMOTIONAL, > >>>> RIGHTS, VALIDFROM, VALIDTO, ADVERTISINGSHOWINFOID, > >>>> GEORIGHTSKINDCODE, MAINCHANNELID, MAINDESCRIPTIONLANGUAGECODE, > >>>> MAINTITLELANGUAGECODE, OVERLAYID, SELECTEDTHUMBNAILID) VALUES > >>>> (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) > >>>> [params=(int) 74, (int) 0, (null) null, (null) null, (null) null, > >>>> (null) null, (null) null, (null) null, (int) 0, (null) null, (null) > >>>> null, (null) null, (null) null, (int) 3, (null) null, (null) null, > >>>> (null) null, (null) null, (null) null] > >>>> [junit-coverage] 8006 pu TRACE [main] openjpa.jdbc.SQL - >>>> 9777317, conn 7891417> [2 ms] spent > >>>> [junit-coverage] ###### 3 I'm a class com.joost.model.show.Show > >>>> [junit-coverage] ###### 4 I'm a class com.joost.model.show.Show > >>>> > >>>> The code after the ###### 2 message is a getId(), and that triggers > >>>> the write to the db. You can see that we write to both > >>>> InventoryItem (the base class) and then VideoShow (java class Show > >>>> maps to the VideoShow table... public class Show extends > >>>> InventoryItem) > >>>> > >>>> However, for the case of "b" within "a", which is a ChannelItem > >>>> within a Channel (both of which extend InventoryItem) I get : > >>>> > >>>> [junit-coverage] ###### 1 I'm a class > >>>> com.joost.model.channel.Channel > >>>> [junit-coverage] ###### 2 I'm a class > >>>> com.joost.model.channel.Channel > >>>> [junit-coverage] ###### 1 I'm a class com.joost.model.ChannelItem > >>>> [junit-coverage] ###### 2 I'm a class com.joost.model.ChannelItem > >>>> [junit-coverage] Nov 15, 2007 4:51:04 PM > >>>> org.springframework.test.AbstractTransactionalSpringContextTests > >>>> endTransaction > >>>> [junit-coverage] INFO: Rolled back transaction after test execution > >>>> [junit-coverage] ------------- ---------------- --------------- > >>>> > >>>> > >>>> so the getId() for the Channel ("a") called after the #### 2 > >>>> message triggers the @PostPersist for the ChannelItem ("b") which > >>>> has a reference to the id for Channel. I think that therefore I > >>>> can conclude that what I'm doing is illegal according to the spec > >>>> > >>>> 3.5.2 : It isimplementation-dependent as to whether callback > >>>> methods are invoked before or after the cascading of the lifecycle > >>>> events to related entities. Applications should not depend on this > >>>> ordering. > >>>> > >>>> and therefore if that's true, I'm sorry for wasting your time :) > >>>> > >>>> Anyone have a clue how I can get out of this mess? > >>>> > >>>> geir > >>>> > >>>> > >>>> > >>>> > >>>> > >>>>> > >>>>> > >>>>>> > >>>>>> b) what is the identity definition on b? > >>>>>> c) if b is using auto-assigned GeneratedValue or its id is being > >>>>>> set by > >>>>>> application? > >>>>>> > >>>>>> -----Original Message----- > >>>>>> From: Geir Magnusson Jr. [mailto:geir@pobox.com] > >>>>>> Sent: Thursday, November 15, 2007 11:10 AM > >>>>>> To: dev@openjpa.apache.org > >>>>>> Subject: @PostPersist woes > >>>>>> > >>>>>> Woe is me :) > >>>>>> > >>>>>> I'm using @PostPersist to create some kind of machine-generated > >>>>>> data for > >>>>>> entities on insert, and I'm running into the following problem > >>>>>> when an > >>>>>> entity for which I called persist() has in it a new, unmanaged > >>>>>> entity. > >>>>>> > >>>>>> [junit-coverage] Caused by: >>>>>> user > >>>>>> error> org.apache.openjpa.util.InvalidStateException: Detected > >>>>>> reentrant flush. Make sure your flush-time instance callback > >>>>>> methods or > >>>>>> event listeners do not invoke any operations that require the in- > >>>>>> progress flush to complete. > >>>>>> [junit-coverage] at > >>>>>> org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java: > >>>>>> 1840) > >>>>>> [junit-coverage] at > >>>>>> org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1615) > >>>>>> [junit-coverage] at > >>>>>> org > >>>>>> .apache > >>>>>> .openjpa > >>>>>> .kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java: > >>>>>> 505) > >>>>>> [junit-coverage] at > >>>>>> org > >>>>>> .apache > >>>>>> .openjpa > >>>>>> .kernel.StateManagerImpl.assignField(StateManagerImpl.java:590) > >>>>>> [junit-coverage] at > >>>>>> org > >>>>>> .apache > >>>>>> .openjpa > >>>>>> .kernel.StateManagerImpl.beforeAccessField(StateManagerImpl.java: > >>>>>> 1451) > >>>>>> [junit-coverage] at > >>>>>> org > >>>>>> .apache > >>>>>> .openjpa > >>>>>> .kernel.StateManagerImpl.accessingField(StateManagerImpl.java: > >>>>>> 1434) > >>>>>> [junit-coverage] at > >>>>>> com.joost.model.InventoryItem.getId(InventoryItem.java) > >>>>>> [junit-coverage] at > >>>>>> com > >>>>>> .joost.model.InventoryItem.initPublicIdIfNull(InventoryItem.java: > >>>>>> 331) > >>>>>> > >>>>>> > >>>>>> in InventoryItem, getId is the PK, and my read of the spec says > >>>>>> that I > >>>>>> am guaranteed to have it in @PostPersist. > >>>>>> > >>>>>> Bug? me doing something wrong? > >>>>>> > >>>>>> geir > >>>>>> > >>>>>> > >>>>>> Notice: This email message, together with any attachments, may > >>>>>> contain information of BEA Systems, Inc., its subsidiaries > >>>>>> and affiliated entities, that may be confidential, > >>>>>> proprietary, copyrighted and/or legally privileged, and is > >>>>>> intended solely for the use of the individual or entity named in > >>>>>> this message. If you are not the intended recipient, and have > >>>>>> received this message in error, please immediately return this by > >>>>>> email and then delete it. > >>>>> > >>>> > >>> > >>> Craig Russell > >>> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo > >>> 408 276-5638 mailto:Craig.Russell@sun.com > >>> P.S. A good JDO? O, Gasp! > >>> > >> > >> > > > > > > > > -- > > Patrick Linskey > > 202 669 5907 > > -- Patrick Linskey 202 669 5907