代码之家  ›  专栏  ›  技术社区  ›  Taylor Leese

google app engine-org.datanucleus.exceptions.nucleusereexception:对象管理器已关闭

  •  6
  • Taylor Leese  · 技术社区  · 14 年前

    为什么下面的代码会导致org.datanucleus.exceptions.nucleusereexception:对象管理器已关闭?异常似乎在query.getResultList()处引发。

    public final void removeUserTokens(final String username) {
        final Query query = entityManager.createQuery(
            "SELECT p FROM PersistentLogin p WHERE username = :username");
        query.setParameter("username", username);
    
        for (Object token : query.getResultList()) {
            entityManager.remove(token);
        }
    }          
    

    例外:

    org.datanucleus.exceptions.NucleusUserException: Object Manager has been closed
     at org.datanucleus.ObjectManagerImpl.assertIsOpen(ObjectManagerImpl.java:3876)
     at org.datanucleus.ObjectManagerImpl.getFetchPlan(ObjectManagerImpl.java:376)
     at org.datanucleus.store.query.Query.getFetchPlan(Query.java:497)
     at org.datanucleus.store.appengine.query.DatastoreQuery$6.apply(DatastoreQuery.java:611)
     at org.datanucleus.store.appengine.query.DatastoreQuery$6.apply(DatastoreQuery.java:610)
     at org.datanucleus.store.appengine.query.LazyResult.resolveNext(LazyResult.java:94)
     at org.datanucleus.store.appengine.query.LazyResult$LazyAbstractListIterator.computeNext(LazyResult.java:215)
     at org.datanucleus.store.appengine.query.AbstractIterator.tryToComputeNext(AbstractIterator.java:132)
     at org.datanucleus.store.appengine.query.AbstractIterator.hasNext(AbstractIterator.java:127)
     at org.datanucleus.store.appengine.query.LazyResult$AbstractListIterator.hasNext(LazyResult.java:169)
     at com.mystuff.service.auth.PersistentTokenRepositoryImpl.removeUserTokens(PersistentTokenRepositoryImpl.java:90)
    

    编辑 :我增加了DataNucleus的日志级别,这就是我看到的。

    FINE: Object Manager "org.datanucleus.ObjectManagerImpl@5d8d3d6c" opened for datastore "org.datanucleus.store.appengine.DatastoreManager@2447e380"
    Feb 25, 2010 7:21:38 AM org.datanucleus.ObjectManagerImpl initialiseLevel1Cache
    FINE: Level 1 Cache of type "weak" initialised
    Feb 25, 2010 7:21:38 AM org.datanucleus.JDOClassLoaderResolver classForName
    FINE: Class "java.lang.PersistentLogin" was not found in the CLASSPATH [Class resolver called from org.datanucleus.util.Imports.resolveClassDeclaration (line=177)]
    Feb 25, 2010 7:21:38 AM org.datanucleus.ObjectManagerImpl disconnectSMCache
    FINE: Level 1 Cache cleared
    Feb 25, 2010 7:21:38 AM org.datanucleus.ObjectManagerImpl postClose
    FINE: Object Manager "org.datanucleus.ObjectManagerImpl@5d8d3d6c" closed
    Feb 25, 2010 7:21:38 AM com.google.apphosting.utils.jetty.JettyLogger warn
    WARNING: /j_spring_security_logout
    Object Manager has been closed
    org.datanucleus.exceptions.NucleusUserException: Object Manager has been closed
     at org.datanucleus.ObjectManagerImpl.assertIsOpen(ObjectManagerImpl.java:3876)
     at org.datanucleus.ObjectManagerImpl.getFetchPlan(ObjectManagerImpl.java:376)
    
    3 回复  |  直到 9 年前
        1
  •  3
  •   Taylor Leese    14 年前

    添加 @Transactional 方法阻止对象管理器关闭。但是,我不知道没有这个为什么它会关闭。

        2
  •  0
  •   Thilo    14 年前

    我不知道为什么,但这似乎与 query.getResultList() 懒惰的装填。很明显,当你打电话的时候,懒惰的负载会崩溃。 remove(token) .

    作为一种解决方案,您能否先收集数组列表中元素的ID/键,然后在单独的循环中将它们从数据存储中删除?

        3
  •  0
  •   alexis    14 年前

    对我有效的解决方案和我在这里发现的bug的描述:

    http://groups.google.com/group/google-appengine-java/browse_thread/thread/945f6ca66c1c587e