Home » Support » Forum » Attempt to execute a query using a closed EntityManager

Attempt to execute a query using a closed EntityManager

#1

Hi again!

Suddenly, my app started to throw this exception. I would really appreciate some advices.

com.objectdb.o.UserException - Attempt to execute a query using a closed EntityManager at com.objectdb.o.MSG.d(MSG.java:61)

The doesn't make any sense. Scenario:
1. JSF page with create form is used for creating an user. Create button is pressed.
2. @RequestScoped ClientB.create() is triggered and executes the following.
3. First statement: @Stateless ClientC.create(and passes the user)
4. Second: LOG.log(Level.INFO, "Created client {0}", c.getId());
Here is when the error happens, when c.getId() is invoked. It doesn't make any sense to thrown an error when Client.getId() method is invoked. id is a long field in Client, so it should be there after Client is set. Id has @Id @GeneratedValue(strategy = GenerationType.IDENTITY).
5. Any ideas why this would happen? @Stateless ClientC has transactional methods. Moreover, it worked until today. I know, it's really strange.
Thank you a lot in advance. This is getting me crazy. ObjectDB 2.5.1 and TomEE 1.5.2

org.apache.myfaces.view.facelets.el.ContextAwareELException: javax.el.ELException: com.objectdb.o._PersistenceException: Attempt to execute a query using a closed EntityManager
at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:108)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:68)
at javax.faces.component.UICommand.broadcast(UICommand.java:120)
at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1028)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:286)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1375)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:38)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.el.ELException: com.objectdb.o._PersistenceException: Attempt to execute a query using a closed EntityManager
at org.apache.el.parser.AstValue.invoke(AstValue.java:291)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:96)
... 27 more
Caused by: com.objectdb.o._PersistenceException: Attempt to execute a query using a closed EntityManager
at com.objectdb.o._PersistenceException.b(_PersistenceException.java:45)
at com.objectdb.o.JPE.g(JPE.java:142)
at com.objectdb.o.ERR.f(ERR.java:60)
at com.objectdb.o.OBC.onObjectDBError(OBC.java:1484)
at com.objectdb.o.ENT.ak(ENT.java:1632)
at com.objectdb.o.ENT.beforeAccess(ENT.java:1123)
at dk.mandecentret.entity.Client.__odbGet_id(Client.java:1)
at dk.mandecentret.entity.Client.getId(Client.java:77)
at dk.mandecentret.boundary.ClientB.create(ClientB.java:68)
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:601)
at org.apache.webbeans.intercept.InterceptorHandler.invoke(InterceptorHandler.java:322)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:117)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:108)
at dk.mandecentret.boundary.ClientB_$$_javassist_4.create(ClientB_$$_javassist_4.java)
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:601)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
... 29 more
Caused by: com.objectdb.o.UserException: Attempt to execute a query using a closed EntityManager
at com.objectdb.o.MSG.d(MSG.java:61)
at com.objectdb.o.OBC.bj(OBC.java:1424)
at com.objectdb.o.QRR.f(QRR.java:124)
at com.objectdb.o.QRR.a(QRR.java:611)
at com.objectdb.o.InvMemberQuery.e(InvMemberQuery.java:139)
at com.objectdb.o.UMR.w(UMR.java:523)
at com.objectdb.o.LDR.H(LDR.java:664)
at com.objectdb.o.LDR.G(LDR.java:615)
at com.objectdb.o.LDR.E(LDR.java:468)
at com.objectdb.o.OBC.UJ(OBC.java:1073)
at com.objectdb.o.OBC.aK(OBC.java:763)
at com.objectdb.o.ENT.beforeAccess(ENT.java:1115)
... 45 more
#2

According to the stack trace, when getId is invoked the state of the Client object indicates that it requires reloading (or refresh). The object is loaded and a query is executed to initialize a mapped by (inverse) field in that object.

This should be avoided when the EntityManager is closed, and it is unclear how it happens.

Please try build 2.5.1_01 that includes an additional check that may prevent reloading in that case.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

Thank you so much. It seems to work with 2.5.1_01. You have just saved my life!

Question: why would it require reloading or refresh, because c.getId() should just return the "long" field which is @Id @GeneratedValue(strategy = GenerationType.IDENTITY)? Shouldn't it be there after the object's persistence/creation transaction is over?

#4

You are right. Apparently accessing an ID field could be handled differently than accessing a non ID field in this context, so we may change this behavior in future versions.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login