Sorry - there are a few minor errors in my interpretation, which doesn't change my problem. Commments inline :

On Jan 3, 2008, at 12:08 AM, Geir Magnusson Jr. wrote:

I can't figure out what I'm doing wrong.

I'm using joined inheritance and have as my base table InventoryItem with Agent and Contributor as subclasses / tables.

I also have a mapping table called Show2Contributor :

mysql> describe Show2Contributor;
+---------------+------------------+------+-----+---------+-------+
| Field         | Type             | Null | Key | Default | Extra |
+---------------+------------------+------+-----+---------+-------+
| showId        | int(11) unsigned | NO   | PRI |         |       |
| contributorId | int(11) unsigned | NO   | PRI |         |       |
+---------------+------------------+------+-----+---------+-------+

where each Show then has some set of contributors, with each contributor containing an agent (and a static thing called a RoleCode, whic is irrelevant).

Now, I have a weird problem. I'm trying to add 3 Contributors to a Show. 2 already are mapped (one will stay, one will not). Two have to be created new and added....

To create the first new contributor, we happen toneed to add a new agent :

2947 TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 16400155 INSERT INTO InventoryItem (uuid, itemType, name, coId, publicId, damId, ownerId, creationDate,, ... 2948 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 11750977 SELECT LAST_INSERT_ID() 2949 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 10285791 INSERT INTO Agent (id, commonName) VALUES (?, ?) [params=(int) 194591, (String) Geir Magnusson Jr.]

so there it creates a new Agent by making the InventoryItem first, getting the autogen ID, and using that to add to the Agent table.

Then it makes a new contributor, using that Agent (id=194591) :

2959 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 14647551 INSERT INTO InventoryItem (uuid, itemType, name, coId, publicId, damId, ownerId, creationDate, ... 2997 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 1112653 SELECT LAST_INSERT_ID() 2997 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 4592108 INSERT INTO Contributor (id, roleCode, agentId) VALUES (?, ?, ?) [params=(int) 194592, (int) 109, (int) 194591]

Fine - so we have a new contributor, id = 194592, with the new agent (id=194591)

Now, remove from the mapping table the Contributor that we don't need :

Sorry - clearly this is just dumping the old mapping entries for the show, id = 13163.


3094 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 15955745 DELETE FROM Show2Contributor WHERE showId = ? [params=(int) 13163]

Now create another Contributor (using an agent we already have) :

3096 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 15187341 INSERT INTO InventoryItem (uuid, itemType, name, coId, publicId, damId, ownerId, creationDate,... 3122 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 9887497 SELECT LAST_INSERT_ID() 3123 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 9788885 INSERT INTO Contributor (id, roleCode, agentId) VALUES (?, ?, ?) [params=(int) 194593, (int) 109, (int) 194573]

So that's the 2nd new Contributor (id=194593)

To review - two new contributors : 194592 and 194593. The third is an old, existing one (happens to be 13163)

Now, OpenJPA then updates a lastModDate for each of the three :

This is an update of the show we're going to map to.

3125 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 12844136 UPDATE InventoryItem SET lastModificationDate = ? WHERE id = ? [params=(Timestamp) 2008-01-02 23:45:48.924, (int) 13163]



3127 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 13915734 UPDATE InventoryItem SET lastModificationDate = ? WHERE id = ? [params=(Timestamp) 2008-01-02 23:45:48.989, (int) 194591] 3128 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 10653126 UPDATE InventoryItem SET lastModificationDate = ? WHERE id = ? [params=(Timestamp) 2008-01-02 23:45:48.989, (int) 194592]

And now seems to screw up adding to the Show2Contributor table - it adds one of them twice (194593), and skips one (194592).

3129 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 8097602 INSERT INTO Show2Contributor (showId, contributorId) VALUES (?, ?) [params=(int) 13163, (int) 194575] 3131 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 9028526 INSERT INTO Show2Contributor (showId, contributorId) VALUES (?, ?) [params=(int) 13163, (int) 194593] 3132 pu TRACE [main] openjpa.jdbc.SQL - <t 8736201, conn 6321587> executing prepstmnt 11857123 INSERT INTO Show2Contributor (showId, contributorId) VALUES (?, ?) [params=(int) 13163, (int) 194593]

This leads to a contraint violation, and the whole thing rolls back.

Um.

Help? :) This happens for both a 1.1.0-SNAPSHOT as well as 1.0.1 release.

TIA

geir




Reply via email to