定义 Java EE 5 使用 bean 管理事务处理提交错误?

发布于 2024-08-31 12:43:22 字数 6781 浏览 14 评论 0原文

我正在使用 GlassFish 2.1 和 2.1.1。

如果我有一个由 @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW) 注释的 bean 方法。完成一些 JPA 操作后,提交在 JTS 的 afterCompletion 阶段失败。

GlassFish 仅记录此失败。并且这个 bean 方法的调用者没有机会知道出了什么问题。

所以我想知道 Java EE 5 服务器在提交时是否必须处理异常是否有任何定义。我预计会出现任何运行时异常。

我正在使用无状态 bean。使用 SessionSynchronization 我可以获得提交失败,如果我使用有状态 bean。是否可以拦截我在界面中声明的异常,以便我可以抛出异常?

这是整个异常堆栈跟踪:

[#|2010-05-06T12:15:54.840+0000|WARNING|sun-appserver2.1|oracle.toplink.essentials.session.file:/C:/glassfish/domains/domain1/applications/j2ee-apps/my-ear-1.0.0-SNAPSHOT/my-jar-1.1.8_jar/-myPu.transaction|_ThreadID=25;_ThreadName=p: thread-pool-1; w: 15;_RequestID=67a475a1-25c3-4416-abea-0d159f715373;|
java.lang.RuntimeException: Got exception during XAResource.end: oracle.jdbc.xa.OracleXAException
    at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.delistResource(J2EETransactionManagerOpt.java:224)
    at com.sun.enterprise.resource.ResourceManagerImpl.unregisterResource(ResourceManagerImpl.java:265)
    at com.sun.enterprise.resource.ResourceManagerImpl.delistResource(ResourceManagerImpl.java:223)
    at com.sun.enterprise.resource.PoolManagerImpl.resourceClosed(PoolManagerImpl.java:400)
    at com.sun.enterprise.resource.ConnectorAllocator$ConnectionListenerImpl.connectionClosed(ConnectorAllocator.java:72)
    at com.sun.gjc.spi.ManagedConnection.connectionClosed(ManagedConnection.java:639)
    at com.sun.gjc.spi.base.ConnectionHolder.close(ConnectionHolder.java:201)
    at com.sun.gjc.spi.jdbc40.ConnectionHolder40.close(ConnectionHolder40.java:519)
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.closeDatasourceConnection(DatabaseAccessor.java:394)
    at oracle.toplink.essentials.internal.databaseaccess.DatasourceAccessor.closeConnection(DatasourceAccessor.java:382)
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.closeConnection(DatabaseAccessor.java:417)
    at oracle.toplink.essentials.internal.databaseaccess.DatasourceAccessor.afterJTSTransaction(DatasourceAccessor.java:115)
    at oracle.toplink.essentials.threetier.ClientSession.afterTransaction(ClientSession.java:119)
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.afterTransaction(UnitOfWorkImpl.java:1841)
    at oracle.toplink.essentials.transaction.AbstractSynchronizationListener.afterCompletion(AbstractSynchronizationListener.java:170)
    at oracle.toplink.essentials.transaction.JTASynchronizationListener.afterCompletion(JTASynchronizationListener.java:102)
    at com.sun.jts.jta.SynchronizationImpl.after_completion(SynchronizationImpl.java:154)
    at com.sun.jts.CosTransactions.RegisteredSyncs.distributeAfter(RegisteredSyncs.java:210)
    at com.sun.jts.CosTransactions.TopCoordinator.afterCompletion(TopCoordinator.java:2585)
    at com.sun.jts.CosTransactions.CoordinatorTerm.commit(CoordinatorTerm.java:433)
    at com.sun.jts.CosTransactions.TerminatorImpl.commit(TerminatorImpl.java:250)
    at com.sun.jts.CosTransactions.CurrentImpl.commit(CurrentImpl.java:623)
    at com.sun.jts.jta.TransactionManagerImpl.commit(TransactionManagerImpl.java:309)
    at com.sun.enterprise.distributedtx.J2EETransactionManagerImpl.commit(J2EETransactionManagerImpl.java:1029)
    at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.commit(J2EETransactionManagerOpt.java:398)
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:3817)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3610)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1379)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1316)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:205)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127)
    at $Proxy127.myNewTxMethod(Unknown Source)
    at mypackage.MyBean2.myMethod(MyBean2.java:197)
    at mypackage.MyBean2.myMethod2(MyBean2.java:166)
    at mypackage.MyBean2.myMethod3(MyBean2.java:105)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
    at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
    at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2920)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4011)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:197)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127)
    at $Proxy158.myMethod3(Unknown Source)
    at mypackage.MyBean3.myMethod4(MyBean3.java:94)
    at mypackage.MyBean3.onMessage(MyBean3.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.security.SecurityUtil$2.run(SecurityUtil.java:181)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.enterprise.security.application.EJBSecurityManager.doAsPrivileged(EJBSecurityManager.java:985)
    at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:186)
    at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2920)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4011)
    at com.sun.ejb.containers.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1111)
    at com.sun.ejb.containers.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:74)
    at com.sun.enterprise.connectors.inflow.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:179)
    at $Proxy192.onMessage(Unknown Source)
    at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:258)
    at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:76)
    at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
|#]

I'm using GlassFish 2.1 and 2.1.1.

If I've a bean method annotated by @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW). After doing some JPA stuff the commit fails in the afterCompletion-Phase of JTS.

GlassFish logs this failure only. And the caller of this bean method has no chance to know something goes wrong.

So I wonder, if there is any definition how a Java EE 5 server has to handle exceptions while commiting. I would expect any runtime exception.

I'm using stateless beans. With SessionSynchronisation I could get the commit failue, if I use statefull beans. Is it possible to intercept, so I can throw an exception, that I've declared in my interface?

This is the whole exception stacktrace:

[#|2010-05-06T12:15:54.840+0000|WARNING|sun-appserver2.1|oracle.toplink.essentials.session.file:/C:/glassfish/domains/domain1/applications/j2ee-apps/my-ear-1.0.0-SNAPSHOT/my-jar-1.1.8_jar/-myPu.transaction|_ThreadID=25;_ThreadName=p: thread-pool-1; w: 15;_RequestID=67a475a1-25c3-4416-abea-0d159f715373;|
java.lang.RuntimeException: Got exception during XAResource.end: oracle.jdbc.xa.OracleXAException
    at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.delistResource(J2EETransactionManagerOpt.java:224)
    at com.sun.enterprise.resource.ResourceManagerImpl.unregisterResource(ResourceManagerImpl.java:265)
    at com.sun.enterprise.resource.ResourceManagerImpl.delistResource(ResourceManagerImpl.java:223)
    at com.sun.enterprise.resource.PoolManagerImpl.resourceClosed(PoolManagerImpl.java:400)
    at com.sun.enterprise.resource.ConnectorAllocator$ConnectionListenerImpl.connectionClosed(ConnectorAllocator.java:72)
    at com.sun.gjc.spi.ManagedConnection.connectionClosed(ManagedConnection.java:639)
    at com.sun.gjc.spi.base.ConnectionHolder.close(ConnectionHolder.java:201)
    at com.sun.gjc.spi.jdbc40.ConnectionHolder40.close(ConnectionHolder40.java:519)
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.closeDatasourceConnection(DatabaseAccessor.java:394)
    at oracle.toplink.essentials.internal.databaseaccess.DatasourceAccessor.closeConnection(DatasourceAccessor.java:382)
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.closeConnection(DatabaseAccessor.java:417)
    at oracle.toplink.essentials.internal.databaseaccess.DatasourceAccessor.afterJTSTransaction(DatasourceAccessor.java:115)
    at oracle.toplink.essentials.threetier.ClientSession.afterTransaction(ClientSession.java:119)
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.afterTransaction(UnitOfWorkImpl.java:1841)
    at oracle.toplink.essentials.transaction.AbstractSynchronizationListener.afterCompletion(AbstractSynchronizationListener.java:170)
    at oracle.toplink.essentials.transaction.JTASynchronizationListener.afterCompletion(JTASynchronizationListener.java:102)
    at com.sun.jts.jta.SynchronizationImpl.after_completion(SynchronizationImpl.java:154)
    at com.sun.jts.CosTransactions.RegisteredSyncs.distributeAfter(RegisteredSyncs.java:210)
    at com.sun.jts.CosTransactions.TopCoordinator.afterCompletion(TopCoordinator.java:2585)
    at com.sun.jts.CosTransactions.CoordinatorTerm.commit(CoordinatorTerm.java:433)
    at com.sun.jts.CosTransactions.TerminatorImpl.commit(TerminatorImpl.java:250)
    at com.sun.jts.CosTransactions.CurrentImpl.commit(CurrentImpl.java:623)
    at com.sun.jts.jta.TransactionManagerImpl.commit(TransactionManagerImpl.java:309)
    at com.sun.enterprise.distributedtx.J2EETransactionManagerImpl.commit(J2EETransactionManagerImpl.java:1029)
    at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.commit(J2EETransactionManagerOpt.java:398)
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:3817)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3610)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1379)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1316)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:205)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127)
    at $Proxy127.myNewTxMethod(Unknown Source)
    at mypackage.MyBean2.myMethod(MyBean2.java:197)
    at mypackage.MyBean2.myMethod2(MyBean2.java:166)
    at mypackage.MyBean2.myMethod3(MyBean2.java:105)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
    at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
    at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2920)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4011)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:197)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127)
    at $Proxy158.myMethod3(Unknown Source)
    at mypackage.MyBean3.myMethod4(MyBean3.java:94)
    at mypackage.MyBean3.onMessage(MyBean3.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.security.SecurityUtil$2.run(SecurityUtil.java:181)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.enterprise.security.application.EJBSecurityManager.doAsPrivileged(EJBSecurityManager.java:985)
    at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:186)
    at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2920)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4011)
    at com.sun.ejb.containers.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1111)
    at com.sun.ejb.containers.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:74)
    at com.sun.enterprise.connectors.inflow.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:179)
    at $Proxy192.onMessage(Unknown Source)
    at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:258)
    at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:76)
    at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
|#]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒芜了季节 2024-09-07 12:43:22

这只是提交后的一个错误,因此事务已经提交。没关系。

It's only an error AFTER commit, so the transaction was already commit. That's okay.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文