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 - <t
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 - <t
9777317, conn 7891417> [1 ms] spent
[junit-coverage] 7997 pu TRACE [main] openjpa.jdbc.SQL - <t
9777317, conn 7891417> executing prepstmnt 13415937
VALUES(IDENTITY_VAL_LOCAL())
[junit-coverage] 7997 pu TRACE [main] openjpa.jdbc.SQL - <t
9777317, conn 7891417> [0 ms] spent
[junit-coverage] 8004 pu TRACE [main] openjpa.jdbc.SQL - <t
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 - <t
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] ------------- ---------------- ---------------
<EXCEPTION>
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:[EMAIL PROTECTED]
Sent: Thursday, November 15, 2007 11:10 AM
To: [email protected]
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: <openjpa-1.0.0-r420667:568756 fatal 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.