With JPOX-1.1.3 and snapshot a Duplicate Entry Exception is thrown when persisting the following graph:
Situation
^
|
Questionnaire---->Dependency--------->Condition
...
Questionnaire questionnaire = new Questionnaire();
Situation situation = new Dependency();
situation.getConditions().add(new Condition());
questionnaire.getSituations().add(situation);
...
pm.makePersistent(questionnaire);
...
<class name="Questionnaire" identity-type="datastore" detachable="true">
<inheritance strategy="new-table"/>
<field name="situations" persistence-modifier="persistent" default-fetch-group="true">
<collection element-type="Situation"/>
</field>
</class>
<class name="Situation" identity-type="datastore" detachable="true">
<inheritance strategy="new-table"/>
<field name="conditions" persistence-modifier="persistent" default-fetch-group="true">
<collection element-type="Condition"/>
</field>
</class>
<class name="Dependency" identity-type="datastore" detachable="true">
<inheritance strategy="new-table"/>
</class>
<class name="Condition" identity-type="datastore" detachable="true">
<inheritance strategy="new-table"/>
</class>
We are still using JPOX-1.1-rc1 where this graph can be persisted.
JPOX log:
31 oct. 2006 10:55:02,812 INFO JPOX.RDBMS.Schema - Catalog "jpox", Schema "" initialised - managing 4 classes
31 oct. 2006 10:55:02,812 DEBUG JPOX.Cache - Level 1 Cache of type "weak" initialised
31 oct. 2006 10:55:02,843 DEBUG JPOX.RDBMS - Connection "
com.mysql.jdbc.Connection@3bc257" opened with isolation level "READ_COMMITTED"
31 oct. 2006 10:55:02,843 DEBUG JPOX.Transaction - Connection
com.mysql.jdbc.Connection@3bc257 started for pessimistic transaction
31 oct. 2006 10:55:02,843 DEBUG JPOX.Transaction - Transaction begun with connection
com.mysql.jdbc.Connection@3bc257
31 oct. 2006 10:55:02,843 DEBUG JPOX.JDO - Making object persistent : "
org.jpox.test.Questionnaire@153f67e"
31 oct. 2006 10:55:02,875 DEBUG JPOX.General - org.jpox.util.WeakValueMap(7145547) size = 0, hits = 0, misses = 34, cleared = 0
31 oct. 2006 10:55:02,875 DEBUG JPOX.General - org.jpox.util.WeakValueMap(3912376) size = 10, hits = 23, misses = 11, cleared = 0
31 oct. 2006 10:55:02,890 DEBUG JPOX.Store.Poid - Creating PoidGenerator instance of org.jpox.store.rdbms.poid.SequenceTablePoidGenerator for org.jpox.test.Questionnaire
31 oct. 2006 10:55:02,906 DEBUG JPOX.RDBMS - Connection "
com.mysql.jdbc.Connection@1d0fafc" opened with isolation level "READ_COMMITTED"
31 oct. 2006 10:55:02,906 DEBUG JPOX.RDBMS - Column "SEQUENCE_TABLE.SEQUENCE_NAME" added to internal representation of table.
31 oct. 2006 10:55:02,906 DEBUG JPOX.RDBMS - Column "SEQUENCE_TABLE.NEXT_VAL" added to internal representation of table.
31 oct. 2006 10:55:02,906 DEBUG JPOX.RDBMS.SQL - SELECT NEXT_VAL FROM SEQUENCE_TABLE WHERE SEQUENCE_NAME=<'org.jpox.test.Questionnaire'> FOR UPDATE
31 oct. 2006 10:55:02,906 DEBUG JPOX.RDBMS.SQL - Execution Time = 0 ms
31 oct. 2006 10:55:02,906 DEBUG JPOX.RDBMS.SQL - UPDATE SEQUENCE_TABLE SET NEXT_VAL=(NEXT_VAL+<5>) WHERE SEQUENCE_NAME=<'org.jpox.test.Questionnaire'>
31 oct. 2006 10:55:02,906 DEBUG JPOX.RDBMS.SQL - Execution Time = 0 ms
31 oct. 2006 10:55:02,968 DEBUG JPOX.RDBMS - Connection "
com.mysql.jdbc.Connection@1d0fafc" closed
31 oct. 2006 10:55:02,968 DEBUG JPOX.Store.Poid - Generated value for field "org.jpox.test.Questionnaire (datastore id)" using strategy="native" (PoidGenerator="org.jpox.store.rdbms.poid.SequenceTablePoidGenerator") : value=6
31 oct. 2006 10:55:02,968 DEBUG JPOX.Cache - Adding object with id "6[OID]org.jpox.test.Questionnaire" to Level 1 cache
31 oct. 2006 10:55:02,968 DEBUG JPOX.General - org.jpox.util.WeakValueMap(20003078) size = 0, hits = 0, misses = 1, cleared = 0
31 oct. 2006 10:55:02,968 DEBUG JPOX.Transaction - "6[OID]org.jpox.test.Questionnaire" : enlisting in transactional cache
31 oct. 2006 10:55:02,968 DEBUG JPOX.General - org.jpox.util.SoftValueMap(32189467) size = 0, hits = 0, misses = 1, cleared = 0
31 oct. 2006 10:55:02,984 DEBUG JPOX.JDO - Inserting object
org.jpox.test.Questionnaire@22279806 of type org.jpox.test.Questionnaire into table QUESTIONNAIRE
31 oct. 2006 10:55:02,984 DEBUG JPOX.RDBMS.SQL - INSERT INTO QUESTIONNAIRE (QUESTIONNAIRE_ID) VALUES (<6>)
31 oct. 2006 10:55:02,984 DEBUG JPOX.RDBMS.SQL - Execution Time = 0 ms
31 oct. 2006 10:55:03,000 DEBUG JPOX.JDO - Making object persistent : "
org.jpox.test.Dependency@175078b"
31 oct. 2006 10:55:03,000 DEBUG JPOX.Store.Poid - Creating PoidGenerator instance of org.jpox.store.rdbms.poid.SequenceTablePoidGenerator for org.jpox.test.Dependency
31 oct. 2006 10:55:03,015 DEBUG JPOX.RDBMS - Connection "
com.mysql.jdbc.Connection@11a75a2" opened with isolation level "READ_COMMITTED"
31 oct. 2006 10:55:03,015 DEBUG JPOX.RDBMS - Column "SEQUENCE_TABLE.SEQUENCE_NAME" added to internal representation of table.
31 oct. 2006 10:55:03,015 DEBUG JPOX.RDBMS - Column "SEQUENCE_TABLE.NEXT_VAL" added to internal representation of table.
31 oct. 2006 10:55:03,015 DEBUG JPOX.RDBMS.SQL - SELECT NEXT_VAL FROM SEQUENCE_TABLE WHERE SEQUENCE_NAME=<'org.jpox.test.Situation'> FOR UPDATE
31 oct. 2006 10:55:03,015 DEBUG JPOX.RDBMS.SQL - Execution Time = 0 ms
31 oct. 2006 10:55:03,015 DEBUG JPOX.RDBMS.SQL - UPDATE SEQUENCE_TABLE SET NEXT_VAL=(NEXT_VAL+<5>) WHERE SEQUENCE_NAME=<'org.jpox.test.Situation'>
31 oct. 2006 10:55:03,015 DEBUG JPOX.RDBMS.SQL - Execution Time = 0 ms
31 oct. 2006 10:55:03,078 DEBUG JPOX.RDBMS - Connection "
com.mysql.jdbc.Connection@11a75a2" closed
31 oct. 2006 10:55:03,078 DEBUG JPOX.Store.Poid - Generated value for field "org.jpox.test.Dependency (datastore id)" using strategy="native" (PoidGenerator="org.jpox.store.rdbms.poid.SequenceTablePoidGenerator") : value=6
31 oct. 2006 10:55:03,078 DEBUG JPOX.Cache - Adding object with id "6[OID]org.jpox.test.Dependency" to Level 1 cache
31 oct. 2006 10:55:03,078 DEBUG JPOX.Transaction - "6[OID]org.jpox.test.Dependency" : enlisting in transactional cache
31 oct. 2006 10:55:03,078 DEBUG JPOX.JDO - Inserting object
org.jpox.test.Dependency@24446859 of type org.jpox.test.Dependency into table SITUATION
31 oct. 2006 10:55:03,078 DEBUG JPOX.RDBMS.SQL - INSERT INTO SITUATION (SITUATION_ID,SITUATIONS_QUESTIONNAIRE_ID_OID,SITUATIONS_INTEGER_IDX) VALUES (<6>,<6>,<0>)
31 oct. 2006 10:55:03,078 DEBUG JPOX.RDBMS.SQL - Execution Time = 0 ms
31 oct. 2006 10:55:03,078 DEBUG JPOX.JDO - Making object persistent : "
org.jpox.test.Condition@1581593"
31 oct. 2006 10:55:03,078 DEBUG JPOX.Store.Poid - Creating PoidGenerator instance of org.jpox.store.rdbms.poid.SequenceTablePoidGenerator for org.jpox.test.Condition
31 oct. 2006 10:55:03,078 DEBUG JPOX.RDBMS - Connection "
com.mysql.jdbc.Connection@176cad3" opened with isolation level "READ_COMMITTED"
31 oct. 2006 10:55:03,078 DEBUG JPOX.RDBMS - Column "SEQUENCE_TABLE.SEQUENCE_NAME" added to internal representation of table.
31 oct. 2006 10:55:03,093 DEBUG JPOX.RDBMS - Column "SEQUENCE_TABLE.NEXT_VAL" added to internal representation of table.
31 oct. 2006 10:55:03,093 DEBUG JPOX.RDBMS.SQL - SELECT NEXT_VAL FROM SEQUENCE_TABLE WHERE SEQUENCE_NAME=<'org.jpox.test.Condition'> FOR UPDATE
31 oct. 2006 10:55:03,093 DEBUG JPOX.RDBMS.SQL - Execution Time = 0 ms
31 oct. 2006 10:55:03,093 DEBUG JPOX.RDBMS.SQL - UPDATE SEQUENCE_TABLE SET NEXT_VAL=(NEXT_VAL+<5>) WHERE SEQUENCE_NAME=<'org.jpox.test.Condition'>
31 oct. 2006 10:55:03,093 DEBUG JPOX.RDBMS.SQL - Execution Time = 0 ms
31 oct. 2006 10:55:03,140 DEBUG JPOX.RDBMS - Connection "
com.mysql.jdbc.Connection@176cad3" closed
31 oct. 2006 10:55:03,140 DEBUG JPOX.Store.Poid - Generated value for field "org.jpox.test.Condition (datastore id)" using strategy="native" (PoidGenerator="org.jpox.store.rdbms.poid.SequenceTablePoidGenerator") : value=6
31 oct. 2006 10:55:03,140 DEBUG JPOX.Cache - Adding object with id "6[OID]org.jpox.test.Condition" to Level 1 cache
31 oct. 2006 10:55:03,140 DEBUG JPOX.Transaction - "6[OID]org.jpox.test.Condition" : enlisting in transactional cache
31 oct. 2006 10:55:03,140 DEBUG JPOX.JDO - Inserting object
org.jpox.test.Condition@22549907 of type org.jpox.test.Condition into table `CONDITION`
31 oct. 2006 10:55:03,140 DEBUG JPOX.JDO - Field "conditions" of object "6[OID]org.jpox.test.Dependency" has been registered for updating when its value PC object is inserted into the datastore.
31 oct. 2006 10:55:03,140 DEBUG JPOX.JDO - Inserting object
org.jpox.test.Dependency@24446859 of type org.jpox.test.Dependency into table DEPENDENCY
31 oct. 2006 10:55:03,140 DEBUG JPOX.RDBMS.SQL - INSERT INTO DEPENDENCY (DEPENDENCY_ID) VALUES (<6>)
31 oct. 2006 10:55:03,140 DEBUG JPOX.RDBMS.SQL - Execution Time = 0 ms
31 oct. 2006 10:55:03,140 DEBUG JPOX.JDO - Field "conditions" of object "6[OID]org.jpox.test.Dependency is being updated now that its value PC object is inserted in the datastore.
31 oct. 2006 10:55:03,140 DEBUG JPOX.JDO - Inserting object
org.jpox.test.Dependency@24446859 of type org.jpox.test.Dependency into table SITUATION
31 oct. 2006 10:55:03,140 DEBUG JPOX.RDBMS.SQL - INSERT INTO SITUATION (SITUATION_ID,SITUATIONS_QUESTIONNAIRE_ID_OID,SITUATIONS_INTEGER_IDX) VALUES (<6>,<6>,<0>)
31 oct. 2006 10:55:03,140 INFO JPOX.JDO - >> Exception thrown persisting objects : Insert request failed: INSERT INTO SITUATION (SITUATION_ID,SITUATIONS_QUESTIONNAIRE_ID_OID,SITUATIONS_INTEGER_IDX) VALUES (?,?,?)
javax.jdo.JDODataStoreException: Insert request failed: INSERT INTO SITUATION (SITUATION_ID,SITUATIONS_QUESTIONNAIRE_ID_OID,SITUATIONS_INTEGER_IDX) VALUES (?,?,?)
at org.jpox.store.rdbms.request.InsertRequest.execute(InsertRequest.java:441)
at org.jpox.store.rdbms.table.ClassTable.insert(ClassTable.java:2461)
at org.jpox.store.rdbms.table.ClassTable.insert(ClassTable.java:2457)
at org.jpox.store.StoreManager.insert(StoreManager.java:910)
at org.jpox.state.StateManagerImpl.internalMakePersistent(StateManagerImpl.java:3579)
at org.jpox.state.StateManagerImpl.flush(StateManagerImpl.java:4762)
at org.jpox.state.StateManagerImpl.insertionCompleted(StateManagerImpl.java:3741)
at org.jpox.state.StateManagerImpl.changeActivityState(StateManagerImpl.java:3661)
at org.jpox.store.rdbms.request.InsertRequest.execute(InsertRequest.java:398)
at org.jpox.store.rdbms.table.ClassTable.insert(ClassTable.java:2461)
at org.jpox.store.StoreManager.insert(StoreManager.java:910)
at org.jpox.state.StateManagerImpl.internalMakePersistent(StateManagerImpl.java:3579)
at org.jpox.state.StateManagerImpl.makePersistent(StateManagerImpl.java:3558)
at org.jpox.AbstractPersistenceManager.internalMakePersistent(AbstractPersistenceManager.java:1178)
at org.jpox.AbstractPersistenceManager.makePersistentInternal(AbstractPersistenceManager.java:1223)
at org.jpox.store.rdbms.scostore.FKListStore.validateElementForWriting(FKListStore.java:1230)
at org.jpox.store.rdbms.scostore.FKListStore.internalAdd(FKListStore.java:771)
at org.jpox.store.rdbms.scostore.AbstractListStore.addAll(AbstractListStore.java:386)
at org.jpox.store.mapping.CollectionMapping.postInsert(CollectionMapping.java:209)
at org.jpox.store.rdbms.request.InsertRequest.execute(InsertRequest.java:450)
at org.jpox.store.rdbms.table.ClassTable.insert(ClassTable.java:2461)
at org.jpox.store.StoreManager.insert(StoreManager.java:910)
at org.jpox.state.StateManagerImpl.internalMakePersistent(StateManagerImpl.java:3579)
at org.jpox.state.StateManagerImpl.makePersistent(StateManagerImpl.java:3558)
at org.jpox.AbstractPersistenceManager.internalMakePersistent(AbstractPersistenceManager.java:1178)
at org.jpox.AbstractPersistenceManager.makePersistent(AbstractPersistenceManager.java:1241)
at org.jpox.test.Main.main(Main.java:40)
NestedThrowablesStackTrace:
java.sql.SQLException: Duplicate entry '6' for key 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1570)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1085)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:670)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1159)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1076)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1061)
at org.jpox.store.rdbms.ParamLoggingPreparedStatement.executeUpdate(ParamLoggingPreparedStatement.java:359)
at org.jpox.store.rdbms.RDBMSManager.executeStatementUpdate(RDBMSManager.java:572)
at org.jpox.store.rdbms.request.InsertRequest.execute(InsertRequest.java:314)
at org.jpox.store.rdbms.table.ClassTable.insert(ClassTable.java:2461)
at org.jpox.store.rdbms.table.ClassTable.insert(ClassTable.java:2457)
at org.jpox.store.StoreManager.insert(StoreManager.java:910)
at org.jpox.state.StateManagerImpl.internalMakePersistent(StateManagerImpl.java:3579)
at org.jpox.state.StateManagerImpl.flush(StateManagerImpl.java:4762)
at org.jpox.state.StateManagerImpl.insertionCompleted(StateManagerImpl.java:3741)
at org.jpox.state.StateManagerImpl.changeActivityState(StateManagerImpl.java:3661)
at org.jpox.store.rdbms.request.InsertRequest.execute(InsertRequest.java:398)
at org.jpox.store.rdbms.table.ClassTable.insert(ClassTable.java:2461)
at org.jpox.store.StoreManager.insert(StoreManager.java:910)
at org.jpox.state.StateManagerImpl.internalMakePersistent(StateManagerImpl.java:3579)
at org.jpox.state.StateManagerImpl.makePersistent(StateManagerImpl.java:3558)
at org.jpox.AbstractPersistenceManager.internalMakePersistent(AbstractPersistenceManager.java:1178)
at org.jpox.AbstractPersistenceManager.makePersistentInternal(AbstractPersistenceManager.java:1223)
at org.jpox.store.rdbms.scostore.FKListStore.validateElementForWriting(FKListStore.java:1230)
at org.jpox.store.rdbms.scostore.FKListStore.internalAdd(FKListStore.java:771)
at org.jpox.store.rdbms.scostore.AbstractListStore.addAll(AbstractListStore.java:386)
at org.jpox.store.mapping.CollectionMapping.postInsert(CollectionMapping.java:209)
at org.jpox.store.rdbms.request.InsertRequest.execute(InsertRequest.java:450)
at org.jpox.store.rdbms.table.ClassTable.insert(ClassTable.java:2461)
at org.jpox.store.StoreManager.insert(StoreManager.java:910)
at org.jpox.state.StateManagerImpl.internalMakePersistent(StateManagerImpl.java:3579)
at org.jpox.state.StateManagerImpl.makePersistent(StateManagerImpl.java:3558)
at org.jpox.AbstractPersistenceManager.internalMakePersistent(AbstractPersistenceManager.java:1178)
at org.jpox.AbstractPersistenceManager.makePersistent(AbstractPersistenceManager.java:1241)
at org.jpox.test.Main.main(Main.java:40)
31 oct. 2006 10:55:03,187 DEBUG JPOX.Transaction - Transaction rolling back with connection
com.mysql.jdbc.Connection@3bc257
31 oct. 2006 10:55:03,187 DEBUG JPOX.JDO.Lifecycle - "6[OID]org.jpox.test.Questionnaire" : P_NEW->null
31 oct. 2006 10:55:03,187 DEBUG JPOX.Transaction - "6[OID]org.jpox.test.Questionnaire" : evicting from transactional cache
31 oct. 2006 10:55:03,187 DEBUG JPOX.JDO - Disconnecting
org.jpox.test.Questionnaire@22279806 from
org.jpox.state.StateManagerImpl@1e845c2
31 oct. 2006 10:55:03,187 DEBUG JPOX.Cache - Removing object with id "6[OID]org.jpox.test.Questionnaire" from Level 1 cache [cache size = 0]
31 oct. 2006 10:55:03,187 DEBUG JPOX.Cache - Removal of object with id "6[OID]org.jpox.test.Questionnaire" failed. Didnt exist in the Level 1 cache.
31 oct. 2006 10:55:03,187 DEBUG JPOX.JDO.Lifecycle - "6[OID]org.jpox.test.Condition" : P_NEW->null
31 oct. 2006 10:55:03,187 DEBUG JPOX.Transaction - "6[OID]org.jpox.test.Condition" : evicting from transactional cache
31 oct. 2006 10:55:03,187 DEBUG JPOX.JDO - Disconnecting
org.jpox.test.Condition@22549907 from
org.jpox.state.StateManagerImpl@125fefa
31 oct. 2006 10:55:03,187 DEBUG JPOX.Cache - Removing object with id "6[OID]org.jpox.test.Condition" from Level 1 cache [cache size = 0]
31 oct. 2006 10:55:03,187 DEBUG JPOX.Cache - Removal of object with id "6[OID]org.jpox.test.Condition" failed. Didnt exist in the Level 1 cache.
31 oct. 2006 10:55:03,187 DEBUG JPOX.JDO.Lifecycle - "6[OID]org.jpox.test.Dependency" : P_NEW->null
31 oct. 2006 10:55:03,187 DEBUG JPOX.Transaction - "6[OID]org.jpox.test.Dependency" : evicting from transactional cache
31 oct. 2006 10:55:03,187 DEBUG JPOX.JDO - Disconnecting
org.jpox.test.Dependency@24446859 from
org.jpox.state.StateManagerImpl@f8f7db
31 oct. 2006 10:55:03,187 DEBUG JPOX.Cache - Removing object with id "6[OID]org.jpox.test.Dependency" from Level 1 cache [cache size = 0]
31 oct. 2006 10:55:03,187 DEBUG JPOX.Cache - Removal of object with id "6[OID]org.jpox.test.Dependency" failed. Didnt exist in the Level 1 cache.
31 oct. 2006 10:55:03,234 DEBUG JPOX.Transaction - Connection
com.mysql.jdbc.Connection@3bc257 closed for pessimistic transaction
31 oct. 2006 10:55:03,234 DEBUG JPOX.RDBMS - Connection "
com.mysql.jdbc.Connection@3bc257" closed
31 oct. 2006 10:55:03,234 DEBUG JPOX.Cache - Level 1 Cache cleared
31 oct. 2006 10:55:03,234 DEBUG JPOX.JDO - Persistence Manager "
org.jpox.PersistenceManagerImpl@76cbf7" closed
31 oct. 2006 10:55:03,234 INFO JPOX.JDO - >> Finished!
Thanks for your help!