0

访问定义如下的字段时,我在 App Engine 上遇到以下异常

@Persistent(mappedBy = "shelf")
@Element(dependent = "true")
private List<ShelfData> shelfData = new ArrayList<ShelfData>();

我通过查看代码推测列表中有一个项目为空。我不知道它是如何到达那里的,因为我所有的插入都包含在事务中。但是,我真正想做的是捕获错误(并忽略它,甚至删除有问题的项目)。

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

修复数据显然是最终的计划,但我不确定如何去做,因为一旦我访问该字段,它就会抛出这个错误。

4

0 回答 0