CDI TransactionPhase.BEFORE_COMPLETION 不与 WebSphere 一起工作

CDI TransactionPhase.BEFORE_COMPLETION not working with WebSphere

我创建 CDI 事件处理程序

    @Singleton
    @Startup
    @ConcurrencyManagement(ConcurrencyManagementType.BEAN)
    @Slf4j
    public class IndicatorEventHandler {
    @Inject
    private Event<TransactionEvent> baeEvent;

    public void onBusinessAccessEntityChangedEvent(@Observes(during = TransactionPhase.BEFORE_COMPLETION) TransactionEvent event) {
            log.info("On business access changed event: {}", event.getEventName());
            calculateIndicators(event);
            try {
                updatePeIndicators(event);
            } catch (ApplicationException e) {
                log.error("Error in ipdate indicators", e);
            }
        }
//some code
    }

我有这个错误

000001ae Transactional E TransactionalEventNotifier notifyObserver В наблюдателе транзакций возникла исключительная ситуация.
                                 org.apache.webbeans.exception.WebBeansException: java.lang.reflect.InvocationTargetException
    at org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:291)
    at org.apache.webbeans.ee.event.TransactionalEventNotifier$AbstractSynchronization.notifyObserver(TransactionalEventNotifier.java:103)
    at org.apache.webbeans.ee.event.TransactionalEventNotifier$BeforeCompletion.beforeCompletion(TransactionalEventNotifier.java:122)
-------------
Caused by: javax.ejb.EJBTransactionRolledbackException: nested exception is: javax.ejb.EJBException: See nested exception; nested exception is: java.lang.IllegalStateException: Preparing
    at com.ibm.ejs.container.BusinessExceptionMappingStrategy.mapCSIException(BusinessExceptionMappingStrategy.java:167)
    at com.ibm.ejs.container.BusinessExceptionMappingStrategy.mapCSITransactionRolledBackException(BusinessExceptionMappingStrategy.java:618)
    at com.ibm.ejs.container.EJSDeployedSupport.mapCSITransactionRolledBackException(EJSDeployedSupport.java:700)
    at com.ibm.ejs.container.EJSContainer.postInvokeRolledbackException(EJSContainer.java:4886)
    at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:4572)`

如果我将 TransactionPhase.BEFORE_COMPLETION 更改为 TransactionPhase.AFTER_COMPLETION 方法可以正常工作。

完整堆栈跟踪

CNTR0019E: EJB threw an unexpected (non-declared) exception during invocation of method "onBusinessAccessEntityChangedEvent". Exception data: java.lang.IllegalStateException: Preparing
at com.ibm.ejs.container.ContainerTx.ensureActive(ContainerTx.java:486)
at com.ibm.ejs.container.ContainerTx.preInvoke(ContainerTx.java:1543)
at com.ibm.ejs.container.EJSContainer.preInvokeActivate(EJSContainer.java:3687)
at com.ibm.ejs.container.EJSContainer.EjbPreInvoke(EJSContainer.java:3047)
at com.mycompany.services.list.indicator.EJSLocalNSGIndicatorEventHandler_5549712c.onBusinessAccessEntityChangedEvent(EJSLocalNSGIndicatorEventHandler_5549712c.java)
at sun.reflect.GeneratedMethodAccessor1260.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.apache.webbeans.ejb.common.proxy.EjbBeanProxyHandler.invoke(EjbBeanProxyHandler.java:204)
at com.mycompany.services.list.indicator.IndicatorEventHandler_$$_javassist_195.onBusinessAccessEntityChangedEvent(IndicatorEventHandler_$$_javassist_195.java)
at sun.reflect.GeneratedMethodAccessor1260.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:285)
at org.apache.webbeans.ee.event.TransactionalEventNotifier$AbstractSynchronization.notifyObserver(TransactionalEventNotifier.java:103)
at org.apache.webbeans.ee.event.TransactionalEventNotifier$BeforeCompletion.beforeCompletion(TransactionalEventNotifier.java:122)
at com.ibm.tx.jta.impl.RegisteredSyncs.coreDistributeBefore(RegisteredSyncs.java:291)
at com.ibm.ws.tx.jta.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:153)
at com.ibm.ws.tx.jta.TransactionImpl.prePrepare(TransactionImpl.java:2384)
at com.ibm.ws.tx.jta.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:588)
at com.ibm.tx.jta.impl.TransactionImpl.processCommit(TransactionImpl.java:1029)
at com.ibm.tx.jta.impl.TransactionImpl.commit(TransactionImpl.java:963)
at com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:439)
at com.ibm.tx.jta.impl.TranManagerSet.commit(TranManagerSet.java:191)
at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:949)
at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:262)
at com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:567)
at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:4486)
at com.mycompany.api.EJSRemote0SLFormServiceImpl_208941b0.unbindForm(EJSRemote0SLFormServiceImpl_208941b0.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.ibm.CORBA.iiop.ClientDelegate.run(ClientDelegate.java:1268)
at java.security.AccessController.doPrivileged(AccessController.java:488)
at com.ibm.CORBA.iiop.ClientDelegate.invoke0(ClientDelegate.java:1265)
at com.ibm.CORBA.iiop.ClientDelegate$ClientDelegate0.invoke(ClientDelegate.java:1502)
at com.sun.proxy.$Proxy541.unbindForm(Unknown Source)
at com.mycompany.api._FormService_Stub.unbindForm(_FormService_Stub.java:1)
at com.mycompany.plugin.utils.FormPluginService.updateModel(FormPluginService.java:380)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.mycompany.plugin.base.ResponseCreator.create(ResponseCreator.java:369)
at com.mycompany.plugin.base.BasePluginService.invokeOperation(BasePluginService.java:299)
at com.mycompany.plugin.base.BasePluginService.execute(BasePluginService.java:263)
at com.mycompany.plugin.utils.FormPluginService.execute(FormPluginService.java:83)
at com.ibm.ecm.util.PluginUtil.invokeService(PluginUtil.java:808)
at com.ibm.ecm.struts.actions.PluginAction.executeBaseAction(PluginAction.java:115)
at com.ibm.ecm.struts.actions.BaseAction.execute(BaseAction.java:227)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at com.ibm.ecm.struts.controller.ControllerServlet.process(ControllerServlet.java:246)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1233)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:782)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:481)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)
at com.ibm.ecm.filters.RequestParamFilter.doFilter(RequestParamFilter.java:79)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:967)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1107)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:949)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1817)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892)

还有这个

 Transactional E TransactionalEventNotifier notifyObserver В наблюдателе транзакций возникла исключительная ситуация.
                                 org.apache.webbeans.exception.WebBeansException: java.lang.reflect.InvocationTargetException
    at org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:291)
    at org.apache.webbeans.ee.event.TransactionalEventNotifier$AbstractSynchronization.notifyObserver(TransactionalEventNotifier.java:103)
    at org.apache.webbeans.ee.event.TransactionalEventNotifier$BeforeCompletion.beforeCompletion(TransactionalEventNotifier.java:122)
    at com.ibm.tx.jta.impl.RegisteredSyncs.coreDistributeBefore(RegisteredSyncs.java:291)
    at com.ibm.ws.tx.jta.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:153)
    at com.ibm.ws.tx.jta.TransactionImpl.prePrepare(TransactionImpl.java:2384)
    at com.ibm.ws.tx.jta.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:588)
    at com.ibm.tx.jta.impl.TransactionImpl.processCommit(TransactionImpl.java:1029)
    at com.ibm.tx.jta.impl.TransactionImpl.commit(TransactionImpl.java:963)
    at com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:439)
    at com.ibm.tx.jta.impl.TranManagerSet.commit(TranManagerSet.java:191)
    at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:949)
    at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:262)
    at com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:567)
    at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:4486)
    at com.mycompany.api.EJSRemote0SLFormServiceImpl_208941b0.unbindForm(EJSRemote0SLFormServiceImpl_208941b0.java)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at com.ibm.CORBA.iiop.ClientDelegate.run(ClientDelegate.java:1268)
    at java.security.AccessController.doPrivileged(AccessController.java:488)
    at com.ibm.CORBA.iiop.ClientDelegate.invoke0(ClientDelegate.java:1265)
    at com.ibm.CORBA.iiop.ClientDelegate$ClientDelegate0.invoke(ClientDelegate.java:1502)
    at com.sun.proxy.$Proxy541.unbindForm(Unknown Source)
    at com.mycompany.api._FormService_Stub.unbindForm(_FormService_Stub.java:1)
    at com.mycompany.plugin.utils.FormPluginService.updateModel(FormPluginService.java:380)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at com.mycompany.plugin.base.ResponseCreator.create(ResponseCreator.java:369)
    at com.mycompany.plugin.base.BasePluginService.invokeOperation(BasePluginService.java:299)
    at com.mycompany.plugin.base.BasePluginService.execute(BasePluginService.java:263)
    at com.mycompany.plugin.utils.FormPluginService.execute(FormPluginService.java:83)
    at com.ibm.ecm.util.PluginUtil.invokeService(PluginUtil.java:808)
    at com.ibm.ecm.struts.actions.PluginAction.executeBaseAction(PluginAction.java:115)
    at com.ibm.ecm.struts.actions.BaseAction.execute(BaseAction.java:227)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    at com.ibm.ecm.struts.controller.ControllerServlet.process(ControllerServlet.java:246)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1233)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:782)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:481)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)
    at com.ibm.ecm.filters.RequestParamFilter.doFilter(RequestParamFilter.java:79)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:967)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1107)
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:949)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1817)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor1260.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:285)
    ... 71 more
Caused by: javax.ejb.EJBTransactionRolledbackException: nested exception is: javax.ejb.EJBException: See nested exception; nested exception is: java.lang.IllegalStateException: Preparing
    at com.ibm.ejs.container.BusinessExceptionMappingStrategy.mapCSIException(BusinessExceptionMappingStrategy.java:167)
    at com.ibm.ejs.container.BusinessExceptionMappingStrategy.mapCSITransactionRolledBackException(BusinessExceptionMappingStrategy.java:618)
    at com.ibm.ejs.container.EJSDeployedSupport.mapCSITransactionRolledBackException(EJSDeployedSupport.java:700)
    at com.ibm.ejs.container.EJSContainer.postInvokeRolledbackException(EJSContainer.java:4886)
    at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:4572)
    at com.mycompany.services.list.indicator.EJSLocalNSGIndicatorEventHandler_5549712c.onBusinessAccessEntityChangedEvent(EJSLocalNSGIndicatorEventHandler_5549712c.java)
    at sun.reflect.GeneratedMethodAccessor1260.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at org.apache.webbeans.ejb.common.proxy.EjbBeanProxyHandler.invoke(EjbBeanProxyHandler.java:204)
    at com.mycompany.services.list.indicator.IndicatorEventHandler_$$_javassist_195.onBusinessAccessEntityChangedEvent(IndicatorEventHandler_$$_javassist_195.java)
    ... 75 more
Caused by: javax.ejb.EJBException: See nested exception; nested exception is: java.lang.IllegalStateException: Preparing
    at com.ibm.ejs.container.util.ExceptionUtil.EJBException(ExceptionUtil.java:475)
    at com.ibm.ejs.container.util.ExceptionUtil.EJBException(ExceptionUtil.java:365)
    at com.ibm.ejs.container.BusinessExceptionMappingStrategy.mapException(BusinessExceptionMappingStrategy.java:392)
    at com.ibm.ejs.container.BusinessExceptionMappingStrategy.setUncheckedException(BusinessExceptionMappingStrategy.java:554)
    at com.ibm.ejs.container.EJSDeployedSupport.setUncheckedException(EJSDeployedSupport.java:520)
    at com.ibm.ejs.container.EJSContainer.preinvokeHandleException(EJSContainer.java:3353)
    at com.ibm.ejs.container.EJSContainer.EjbPreInvoke(EJSContainer.java:3098)
    ... 81 more
Caused by: java.lang.IllegalStateException: Preparing
    at com.ibm.ejs.container.ContainerTx.ensureActive(ContainerTx.java:486)
    at com.ibm.ejs.container.ContainerTx.preInvoke(ContainerTx.java:1543)
    at com.ibm.ejs.container.EJSContainer.preInvokeActivate(EJSContainer.java:3687)
    at com.ibm.ejs.container.EJSContainer.EjbPreInvoke(EJSContainer.java:3047)
    ... 81 more

不幸的是,这是一个合法的错误,已在 WebSphere 9.0 版本中修复。