title: JPA Unexpected exception in beforeCompletion in Weblogic 12c
body: <p>During the execution of a pure JPA managed Transaction, I fetch an Entity A from the database using a Named Query, and after few updates in its state, I merge the A entity again. The result of the merge is a correct merged instance of the Entity, but when the method commits, I have the following exception:</p>
  
  <pre><code>weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion: sync=org.eclipse.persistence.transaction.JTASynchronizationListener@76d1f39e
  PersistenceUtil.getIdentifier(entity) was called with object [...EntityA@6d5f707] which is not a persistent object.
          at weblogic.transaction.internal.TransactionImpl.throwRollbackException(TransactionImpl.java:2122)
          at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:378)
          at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:264)
          at weblogic.ejb.container.internal.BaseLocalObject.postInvoke1(BaseLocalObject.java:316)
          at weblogic.ejb.container.internal.BaseLocalObject.__WL_postInvokeTxRetry(BaseLocalObject.java:195)
          at weblogic.ejb.container.internal.BaseWSLocalObject.__WL_postInvokeTxRetry(BaseWSLocalObject.java:157)
          at weblogic.ejb.container.internal.WSOMethodInvoker.invoke(WSOMethodInvoker.java:40)
          at test.service.PreferencesDSService_y4ih7g_WSOImpl.__WL_savePreferences_WS(Unknown Source)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at weblogic.wsee.server.ejb.WsEjb.invoke(WsEjb.java:55)
          at weblogic.wsee.jaxws.WLSEjbInstanceResolver$WLSEjbInvoker.invoke(WLSEjbInstanceResolver.java:196)
          at weblogic.wsee.jaxws.WLSInstanceResolver$WLSInvoker.invoke(WLSInstanceResolver.java:93)
          at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:149)
          at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:88)
          at weblogic.wsee.jaxws.security.AuthorizationTube$RunAsWrapperTube$1.run(AuthorizationTube.java:293)
          at weblogic.wsee.jaxws.security.AuthorizationTube$RunAsWrapperTube$1.run(AuthorizationTube.java:291)
          at java.security.AccessController.doPrivileged(Native Method)
          at javax.security.auth.Subject.doAs(Subject.java:360)
          at weblogic.wsee.jaxws.security.AuthorizationTube$RunAsWrapperTube.processRequest(AuthorizationTube.java:290)
          at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
          at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
          at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
          at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
          at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:419)
          at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:868)
          at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:422)
          at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:169)
          at weblogic.wsee.jaxws.WLSServletAdapter.handle(WLSServletAdapter.java:246)
          at weblogic.wsee.jaxws.HttpServletAdapter$AuthorizedInvoke.run(HttpServletAdapter.java:667)
          at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:370)
          at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:163)
          at weblogic.wsee.util.ServerSecurityHelper.authenticatedInvoke(ServerSecurityHelper.java:108)
          at weblogic.wsee.jaxws.HttpServletAdapter$3.run(HttpServletAdapter.java:286)
          at weblogic.wsee.jaxws.HttpServletAdapter.post(HttpServletAdapter.java:295)
          at weblogic.wsee.jaxws.JAXWSServlet.doRequest(JAXWSServlet.java:128)
          at weblogic.servlet.http.AbstractAsyncServlet.service(AbstractAsyncServlet.java:103)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
          at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286)
          at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260)
          at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137)
          at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350)
          at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
          at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
          at oracle.security.jps.ee.http.JpsAbsFilter$3.run(JpsAbsFilter.java:172)
          at java.security.AccessController.doPrivileged(Native Method)
          at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
          at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:650)
          at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:110)
          at oracle.security.jps.ee.http.JpsAbsFilter.doFilterInternal(JpsAbsFilter.java:273)
          at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:147)
          at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:94)
          at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
          at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:248)
          at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
          at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3706)
          at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3672)
          at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:328)
          at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)
          at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
          at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
          at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2443)
          at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2291)
          at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2269)
          at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1705)
          at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1665)
          at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:272)
          at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:352)
          at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:337)
          at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:57)
          at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
          at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:652)
          at weblogic.work.ExecuteThread.execute(ExecuteThread.java:420)
          at weblogic.work.ExecuteThread.run(ExecuteThread.java:360)
  </code></pre>
  
  <p>How can a Managed Entity not be a persistent Object? The persistence.xml file has the entity inside, the named query on this entity executed correctly, and the merge also executed successfully.</p>
  
  <p>I use a Weblogic server 12.2.1.3.0. Eclipselink for JPA engine and JEE7 with Java 8.
  The strange thing is that if I update the deployment in WebLogic even without providing a new EAR, the problem is solved.</p>
  
  <p>Any hint will be beneficial.</p>