I am trying to delete multiple entities given a List of Keys, I.e.:
List keys = obj.getKeys(); pm.deletePersistentAll(keys);
However, when I try to delete the entities I get the following exception:
javax.jdo.JDOUserException: One or more instances could not be deleted
at org.datanucleus.jdo.JDOPersistenceManager.deletePersistentAll(JDOPersistenceManager.java:809)
at org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManager.access$301(DatastoreJDOPersistenceManager.java:39)
at org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManage开发者_运维问答r$2.call(DatastoreJDOPersistenceManager.java:112)
at org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManager$2.call(DatastoreJDOPersistenceManager.java:110)
at org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManager$BatchManagerWrapper.call(DatastoreJDOPersistenceManager.java:125)
at org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManager$BatchManagerWrapper.access$200(DatastoreJDOPersistenceManager.java:121)
at org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManager.deletePersistentAll(DatastoreJDOPersistenceManager.java:110)
NestedThrowablesStackTrace: org.datanucleus.jdo.exceptions.ClassNotPersistenceCapableException: The class "The class "com.google.appengine.api.datastore.Key" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found." is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data for the class is not found.
at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:241)
Has anyone experienced this before? I've made sure my classes are enhanced and that all Class's have been marked as PersistenceCapable.
Thanks
You can only delete a persistent object (what you pass in to pm.deletePersistentAll). A "Key" is not a persistent object
To delete an entity by key, try
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
ds.delete(key)
精彩评论