访问定义为
的字段时,我在App Engine上遇到以下异常@Persistent(mappedBy = "shelf")
@Element(dependent = "true")
private List<ShelfData> shelfData = new ArrayList<ShelfData>();
我假设从the code看到列表中有一个空项。如何到达那里我不知道,因为我的所有插入都包含在事务中。但是,我真正想要做的是捕获错误(并忽略它,甚至删除有问题的项目)。
Uncaught exception from servlet
java.lang.NullPointerException
at com.google.appengine.api.datastore.AsyncDatastoreServiceImpl.doBatchGetBySize(AsyncDatastoreServiceImpl.java:306)
at com.google.appengine.api.datastore.AsyncDatastoreServiceImpl.get(AsyncDatastoreServiceImpl.java:275)
at com.google.appengine.api.datastore.DatastoreServiceImpl$1.runInternal(DatastoreServiceImpl.java:68)
at com.google.appengine.api.datastore.DatastoreServiceImpl$1.runInternal(DatastoreServiceImpl.java:65)
at com.google.appengine.api.datastore.TransactionRunner.runInTransaction(TransactionRunner.java:29)
at com.google.appengine.api.datastore.DatastoreServiceImpl.get(DatastoreServiceImpl.java:65)
at com.google.appengine.datanucleus.WrappedDatastoreService.get(WrappedDatastoreService.java:80)
at com.google.appengine.datanucleus.FetchFieldManager.getCollectionFromDatastoreObject(FetchFieldManager.java:666)
at com.google.appengine.datanucleus.FetchFieldManager.fetchRelationField(FetchFieldManager.java:483)
at com.google.appengine.datanucleus.FetchFieldManager.fetchObjectField(FetchFieldManager.java:405)
at org.datanucleus.state.AbstractStateManager.replacingObjectField(AbstractStateManager.java:2353)
at com.myapp.model.Shelf.jdoReplaceField(Shelf.java)
at com.myapp.model.Shelf.jdoReplaceFields(Shelf.java)
at org.datanucleus.state.JDOStateManager.replaceFields(JDOStateManager.java:1935)
at org.datanucleus.state.JDOStateManager.replaceFields(JDOStateManager.java:1962)
at com.google.appengine.datanucleus.DatastorePersistenceHandler.fetchObject(DatastorePersistenceHandler.java:567)
at org.datanucleus.state.JDOStateManager.loadFieldsFromDatastore(JDOStateManager.java:1638)
at org.datanucleus.state.JDOStateManager.loadSpecifiedFields(JDOStateManager.java:1240)
at org.datanucleus.state.JDOStateManager.isLoaded(JDOStateManager.java:1728)
at com.myapp.model.Shelf.jdoGetshelfData(Shelf.java)
at com.myapp.model.Shelf.getShelfData(Shelf.java:137)
...
修复数据显然是最终的计划,但我不知道如何解决这个问题,因为一旦我访问该字段就会抛出此错误。