In my app I have a certain control flow that goes like this:
DAO object = persistenceManager.getObjectById(DAO.class, id);
...
persistenceManager.deletePersistent(anotherReferenceToObject);
...
DAO aThirdObjectReference = persistenceManager.getObjectById(DAO.class, id);
These are all in different scopes, but the persistenceManager
references all point to the same PersistenceManager
.
The problem comes in when the third DAO object turns out to be the same as the second object. The PersistenceManager
happily returns the same object that was just deleted, but I need to know it was deleted before I try accessing or changing parts of it!
I don't want to close the pm because it's important for other reasons to keep it open. Is there any way to tell if an object has been the parameter to deletePersistent
?
As DataNucleus pointed out, I can test for prior deletion with:
JDOHelper.getObjectState(object).equals(ObjectState.PERSISTENT_DELETED)
This will return true after object
has been deleted even if the transaction has not been committed and the pm has not been flushed.