org.datanucleus.exceptions.NucleusUserException: Object Manager has been closed

醉酒当歌 提交于 2020-01-15 15:09:50

问题


I am getting the following error message:

org.datanucleus.exceptions.NucleusUserException: Object Manager has been closed

I have read up on everything I could find on it but I still don't understand what is causing it. I am about to give up and switch to an SQL DB if I cannot resolve this simple issue. Yes I am closing the pm:

static void persistAll(Object[] objs) {

PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
  tx.begin();
  for (Object o : objs)
    pm.makePersistent(o);
  //pm.makePersistentAll(objs);
  tx.commit();
} finally {
  if (tx.isActive())
    tx.rollback();
  pm.close();
}

}

I've made my stuff detachable, and I have detached my objects where I thought I had to. What can I do now??? I'm completely stuck on this one!!! DataNucleus, please help!!!

JG

I have tried adding the Store's List<> fields to the default fetch group and I get the following warning errors from Jetty when debugging my application. I am going to have to try "touching" the fields instead when I fetch the stuff. (?)

Jan 29, 2012 1:29:30 PM org.datanucleus.store.appengine.MetaDataValidator warn
WARNING: Meta-data warning for com.foobar.foo.Store.sales: The datastore does not support joins and therefore cannot honor requests to place related objects in the default fetch group.  The field will be fetched lazily on first access.  You can modify this warning by setting the datanucleus.appengine.ignorableMetaDataBehavior property in your config.  A value of NONE will silence the warning.  A value of ERROR will turn the warning into an exception.
Jan 29, 2012 1:29:30 PM org.datanucleus.store.appengine.MetaDataValidator warn
WARNING: Meta-data warning for com.foobar.foo.Store.shipments: The datastore does not support joins and therefore cannot honor requests to place related objects in the default fetch group.  The field will be fetched lazily on first access.  You can modify this warning by setting the datanucleus.appengine.ignorableMetaDataBehavior property in your config.  A value of NONE will silence the warning.  A value of ERROR will turn the warning into an exception.
Jan 29, 2012 1:29:30 PM org.datanucleus.store.appengine.MetaDataValidator warn
WARNING: Meta-data warning for com.foobar.foo.Store.users: The datastore does not support joins and therefore cannot honor requests to place related objects in the default fetch group.  The field will be fetched lazily on first access.  You can modify this warning by setting the datanucleus.appengine.ignorableMetaDataBehavior property in your config.  A value of NONE will silence the warning.  A value of ERROR will turn the warning into an exception.

I am getting a NullPointerException from pm.makePersistent(store) even though I've checked with the debugger that store is not null (but, since the default fetch group is not working it may be that some of those subfields were null somehow (?)


回答1:


I suspect that your issue relates to trying to access the value of a field which is lazily loaded. If you do this after the PersistenceManager is closed, it will be an error. For example, lazy loading is the default for child objects in a JDO owned relationship. Make sure that you fetch or access ("touch") such content before closing the pm and detaching the object. With an owned one-to-one relationship, you can also add the child field to the 'default fetch group' so it's retrieved and loaded with the parent.

There's more of a discussion on this here: http://code.google.com/appengine/docs/java/datastore/jdo/relationships.html#Owned_One_to_One_Relationships



来源:https://stackoverflow.com/questions/9049491/org-datanucleus-exceptions-nucleususerexception-object-manager-has-been-closed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!