我正在开发一个带有appengine后端的android应用程序。在我的一个端点方法中,我查询数据存储区以检索实体,如下所示:
try {
mgr.getTransaction().begin();
bookList = (List<Book>) q.getResultList();
mgr.getTransaction().commit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
mgr.close();
}
我在尝试从客户端应用程序进行查询时遇到异常:
com.google.api.server.spi.SystemService invokeServiceMethod: Transaction is still active. You should always close your transactions correctly using commit() or rollback().
javax.persistence.PersistenceException: Transaction is still active. You should always close your transactions correctly using commit() or rollback().
at org.datanucleus.jpa.NucleusJPAHelper.getJPAExceptionForJDOException(NucleusJPAHelper.java:195)
at org.datanucleus.jpa.EntityManagerImpl.close(EntityManagerImpl.java:157)
at org.datanucleus.store.appengine.jpa.DatastoreEntityManager.close(DatastoreEntityManager.java:62)
at com.example.bookemon.BookEndpoint.searchBook(BookEndpoint.java:414)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:45)
at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:359)
at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:124)
at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:82)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:438)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:445)
at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:309)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:301)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:442)
at java.lang.Thread.run(Thread.java:724)
Caused by: javax.jdo.JDOUserException: Transaction is still active. You should always close your transactions correctly using commit() or rollback().
FailedObject:org.datanucleus.jdo.JDOPersistenceManager@859b59
at org.datanucleus.jdo.JDOPersistenceManager.close(JDOPersistenceManager.java:277)
at org.datanucleus.jpa.EntityManagerImpl.close(EntityManagerImpl.java:153)
... 34 more
为什么我会收到此异常?