2011-08-14 29 views
0

我想給鍵列表刪除多個實體,即:類「類‘com.google.appengine.api.datastore.Key’不是可持久化

List keys = obj.getKeys(); pm.deletePersistentAll(keys); 

然而,當我嘗試刪除我得到下面的異常的實體:

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.DatastoreJDOPersistenceManager$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) 

有沒有人經歷過這個,我確信我的類增強,所有類的已被標記爲PersistenceCapable

感謝?

回答

0

你只能刪除一個持久對象(你傳遞給pm.deletePersistentAll的東西)。 「鑰匙」是不是一個持久化對象

+0

請問有沒有辦法通過其鍵刪除實體?似乎有點奇怪,我必須首先加載每個對象才能刪除它。 – Mylo

+0

pm.deletePersistent也處理級聯刪除等。從數據存儲中刪除一些東西會給孤兒和不正確的關係帶來風險,因此爲什麼任何理智的對象持久性API都不會允許它。您可以執行Query q = pm.newQuery(...)來選擇要刪除的對象並調用q.deletePersistentAll()。 – DataNucleus

0

要刪除的密鑰的實體,嘗試

DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); 
ds.delete(key) 
+0

如果一些其他對象引用了這個(例如使用GAE/J最新的存儲版本,則父母持有孩子的密鑰),那麼這樣做會留下尾隨引用。 – DataNucleus

相關問題