With two classes A, Base where
'Base' 1-to-many (bidir) 'A'
Create two A objects (storedA, storedA1), both refer to a single Base object which has a collection of references back to the A's.
Persist, commit Txn
Auto detach on commit is enabled
makePersistent(storedA); // works fine
makePersistent(storedA1);// approximately 25% of the time the following exception is thrown:
INFO: Exception thrown
Attempt to attach object "
org.datanucleus.test.A@13816e0" to persistence yet another persistent object with this identity already exists enlisted in this transaction
org.datanucleus.exceptions.NucleusUserException: Attempt to attach object "
org.datanucleus.test.A@13816e0" to persistence yet another persistent object with this identity already exists enlisted in this transaction
at org.datanucleus.ObjectManagerImpl.attachObject(ObjectManagerImpl.java:2011)
at org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.java:1580)
at org.datanucleus.ObjectManagerImpl.persistObject(ObjectManagerImpl.java:1439)
at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:726)
at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:751)
If you run the test case about 4-5 times you should see the exception occur at least once.
I'm not sure if the exception is to be expected or not - but surely it shouldn't be a case of occurring sometimes and not occurring others.
Interesting parts of the datanucleus.properties file are:
javax.jdo.option.Optimistic=true
javax.jdo.option.RetainValues=false
javax.jdo.option.RestoreValues=true
javax.jdo.option.NontransactionalRead=false
datanucleus.DetachAllOnCommit=true
datanucleus.CopyOnAttach=false
# Seems to work ok if CopyOnAttach is set to true and we use
storedA = pm.makePersistent(storedA);
storedA1 = pm.makePersistent(storedA1);
instead of not copying on attach.