当前位置: 首页 > 知识库问答 >
问题:

Resin+Oracle+[Spring]+XA事务REQUIRES_NEW-内部事务提交失败

岳嘉悦
2023-03-14

您能否帮助解决Resin+Oracle上XA事务的问题:

我们有WebApp,它必须执行涉及Oracle11.2.0.1和EHCache2.7的业务事务。(实际上可能有各种组合--两个不同的Oracle数据源(不同的模式),带有/不带有Ehcache,等等)。这就是从普通JDBC使用切换到JTA事务划分的原因。

public void doOuterTransaction() throws Throwable {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("myTx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES);
    TransactionStatus status = txManager.getTransaction(def);
    Connection connection = null;
    Cache cache = null;
    try {
        cache = ...; // get cache from CacheManager
        connection = myDataSource.getConnection(); // or "DataSourceUtils.getConnection(myDataSource)" to guarantee same dbConnection from Spring
        // some business logic
        doInnerTransaction();
        // some business logic
        txManager.commit(status);
    } catch (Throwable ex) {
        txManager.rollback(status);
        throw ex;
    } finally {
        if (connection!=null) {
            connection.close();
        }
    }
}

public void doInnerTransaction() throws Throwable {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("myTx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    TransactionStatus status = txManager.getTransaction(def);
    Connection connection = null;
    Cache cache = null;
    try {
        cache = ...; // get cache from CacheManager
        connection = myDataSource.getConnection(); // or "DataSourceUtils.getConnection(myDataSource)" to guarantee same dbConnection from Spring
        // some business logic
        txManager.commit(status);
    } catch (Throwable ex) {
        txManager.rollback(status);
        throw ex;
    } finally {
        if (connection!=null) {
            connection.close();
        }
    }
}
<database>
<name>my_xa_datasource</name>
<jndi-name>jdbc/my_xa</jndi-name>
<driver>
    <type>oracle.jdbc.xa.client.OracleXADataSource</type>
    <url>${MY_DB_URL}</url>
    <user>${MY_DB_USERNAME}</user>
    <password>${MY_DB_PASSWORD}</password>
</driver>
<max-connections>50</max-connections>
<max-idle-time>60s</max-idle-time>
<max-active-time>24h</max-active-time>
<max-overflow-connections>15</max-overflow-connections>
<ping>true</ping>
<ping-table>DUAL</ping-table>
<ping-interval>240s</ping-interval>
<transaction-timeout>24h</transaction-timeout>
<xa>true</xa>
</database>

>

  • 在外部事务中使用Ehcache访问,在内部事务中只使用DB访问,即使在内部事务中使用REQUIRES_NEW也可以很好地工作。

    在外部事务中或在两个事务中使用数据库访问的情况(无论涉及多少数据源,即使数据源的使用不与事务边界重叠),内部事务的提交会产生以下错误:

    _

    ch.sc.common.ShortAGRuntimeException: org.springframework.transaction.TransactionSystemException:
    JTA failure on commit; nested exception is com.caucho.transaction.SystemExceptionWrapper:
    XA_RMERR: Resource manager error.
    at ch.sc.glibs.mytest.MyTestServlet.doGet(MyTestServlet.java:34)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:120)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:97)
    at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:109)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at com.caucho.server.security.SecurityFilterChain.doFilter(SecurityFilterChain.java:132)
    at com.caucho.server.webapp.WebAppListenerFilterChain.doFilter(WebAppListenerFilterChain.java:114)
    at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:156)
    at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:95)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:289)
    at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:838)
    at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:1309)
    at com.caucho.network.listen.TcpSocketLink.handleRequest(TcpSocketLink.java:1265)
    at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:1249)
    at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:1157)
    at com.caucho.network.listen.TcpSocketLink.handleAcceptTaskImpl(TcpSocketLink.java:956)
    at com.caucho.network.listen.ConnectionTask.runThread(ConnectionTask.java:117)
    at com.caucho.network.listen.ConnectionTask.run(ConnectionTask.java:93)
    at com.caucho.network.listen.SocketLinkThreadLauncher.handleTasks(SocketLinkThreadLauncher.java:169)
    at com.caucho.network.listen.TcpSocketAcceptThread.run(TcpSocketAcceptThread.java:61)
    at com.caucho.env.thread2.ResinThread2.runTasks(ResinThread2.java:173)
    at com.caucho.env.thread2.ResinThread2.run(ResinThread2.java:118)
    Caused by: org.springframework.transaction.TransactionSystemException:
    JTA failure on commit; nested exception is com.caucho.transaction.SystemExceptionWrapper:
    XA_RMERR: Resource manager error.
    at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1025)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    at ch.sc.glibs.mytest.MyTxTest.test3(MyTxTest.java:155)
    at ch.sc.glibs.mytest.MyTxTest.doMainComplexTx(MyTxTest.java:81)
    at ch.sc.glibs.mytest.MyTxTest.doTxTest(MyTxTest.java:50)
    at ch.sc.glibs.mytest.MyTxTest__ResinScopeProxy.doTxTest(Unknown Source)
    at ch.sc.glibs.mytest.MyTestServlet.doGet(MyTestServlet.java:32)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:120)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:97)
    at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:109)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at com.caucho.server.security.SecurityFilterChain.doFilter(SecurityFilterChain.java:132)
    at com.caucho.server.webapp.WebAppListenerFilterChain.doFilter(WebAppListenerFilterChain.java:114)
    at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:156)
    at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:95)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:289)
    at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:838)
    at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:1309)
    at com.caucho.network.listen.TcpSocketLink.handleRequest(TcpSocketLink.java:1265)
    at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:1249)
    at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:1157)
    at com.caucho.network.listen.TcpSocketLink.handleAcceptTaskImpl(TcpSocketLink.java:956)
    at com.caucho.network.listen.ConnectionTask.runThread(ConnectionTask.java:117)
    at com.caucho.network.listen.ConnectionTask.run(ConnectionTask.java:93)
    at com.caucho.network.listen.SocketLinkThreadLauncher.handleTasks(SocketLinkThreadLauncher.java:169)
    at com.caucho.network.listen.TcpSocketAcceptThread.run(TcpSocketAcceptThread.java:61)
    at com.caucho.env.thread2.ResinThread2.runTasks(ResinThread2.java:173)
    at com.caucho.env.thread2.ResinThread2.run(ResinThread2.java:118)
    Caused by: com.caucho.transaction.SystemExceptionWrapper: XA_RMERR: Resource
    manager error.
    at com.caucho.transaction.TransactionImpl.heuristicException(TransactionImpl.java:1040)
    at com.caucho.transaction.TransactionImpl.commitResources(TransactionImpl.java:931)
    at com.caucho.transaction.TransactionImpl.commit(TransactionImpl.java:886)
    at com.caucho.transaction.TransactionManagerImpl.commit(TransactionManagerImpl.java:324)
    at com.caucho.transaction.UserTransactionImpl.commit(UserTransactionImpl.java:363)
    at com.caucho.transaction.UserTransactionProxy.commit(UserTransactionProxy.java:171)
    at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1009)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    at ch.sc.glibs.mytest.MyTxTest.test3(MyTxTest.java:155)
    at ch.sc.glibs.mytest.MyTxTest.doMainComplexTx(MyTxTest.java:81)
    at ch.sc.glibs.mytest.MyTxTest.doTxTest(MyTxTest.java:50)
    at ch.sc.glibs.mytest.MyTxTest__ResinScopeProxy.doTxTest(Unknown Source)
    at ch.sc.glibs.mytest.MyTestServlet.doGet(MyTestServlet.java:32)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:120)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:97)
    at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:109)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at com.caucho.server.security.SecurityFilterChain.doFilter(SecurityFilterChain.java:132)
    at com.caucho.server.webapp.WebAppListenerFilterChain.doFilter(WebAppListenerFilterChain.java:114)
    at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:156)
    at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:95)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:289)
    at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:838)
    at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:1309)
    at com.caucho.network.listen.TcpSocketLink.handleRequest(TcpSocketLink.java:1265)
    at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:1249)
    at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:1157)
    at com.caucho.network.listen.TcpSocketLink.handleAcceptTaskImpl(TcpSocketLink.java:956)
    at com.caucho.network.listen.ConnectionTask.runThread(ConnectionTask.java:117)
    at com.caucho.network.listen.ConnectionTask.run(ConnectionTask.java:93)
    at com.caucho.network.listen.SocketLinkThreadLauncher.handleTasks(SocketLinkThreadLauncher.java:169)
    at com.caucho.network.listen.TcpSocketAcceptThread.run(TcpSocketAcceptThread.java:61)
    at com.caucho.env.thread2.ResinThread2.runTasks(ResinThread2.java:173)
    at com.caucho.env.thread2.ResinThread2.run(ResinThread2.java:118)
    Caused by: oracle.jdbc.xa.OracleXAException
    at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1110)
    at oracle.jdbc.xa.client.OracleXAResource.end(OracleXAResource.java:436)
    at com.caucho.sql.DisjointXAResource.end(DisjointXAResource.java:105)
    at com.caucho.env.dbpool.ManagedPoolItem.endResource(ManagedPoolItem.java:1017)
    at com.caucho.env.dbpool.ManagedPoolItem.commit(ManagedPoolItem.java:957)
    at com.caucho.transaction.TransactionImpl.commitResources(TransactionImpl.java:924)
    at com.caucho.transaction.TransactionImpl.commit(TransactionImpl.java:886)
    at com.caucho.transaction.TransactionManagerImpl.commit(TransactionManagerImpl.java:324)
    at com.caucho.transaction.UserTransactionImpl.commit(UserTransactionImpl.java:363)
    at com.caucho.transaction.UserTransactionProxy.commit(UserTransactionProxy.java:171)
    at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1009)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    at ch.sc.glibs.mytest.MyTxTest.test3(MyTxTest.java:155)
    at ch.sc.glibs.mytest.MyTxTest.doMainComplexTx(MyTxTest.java:81)
    at ch.sc.glibs.mytest.MyTxTest.doTxTest(MyTxTest.java:50)
    at ch.sc.glibs.mytest.MyTxTest__ResinScopeProxy.doTxTest(Unknown Source)
    at ch.sc.glibs.mytest.MyTestServlet.doGet(MyTestServlet.java:32)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:120)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:97)
    at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:109)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at ch.sc.common.http.filters.RegexpFilteringProxyFilter.doFilter(RegexpFilteringProxyFilter.java:65)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at com.caucho.server.security.SecurityFilterChain.doFilter(SecurityFilterChain.java:132)
    at com.caucho.server.webapp.WebAppListenerFilterChain.doFilter(WebAppListenerFilterChain.java:114)
    at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:156)
    at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:95)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:289)
    at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:838)
    at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:1309)
    at com.caucho.network.listen.TcpSocketLink.handleRequest(TcpSocketLink.java:1265)
    at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:1249)
    at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:1157)
    at com.caucho.network.listen.TcpSocketLink.handleAcceptTaskImpl(TcpSocketLink.java:956)
    at com.caucho.network.listen.ConnectionTask.runThread(ConnectionTask.java:117)
    at com.caucho.network.listen.ConnectionTask.run(ConnectionTask.java:93)
    at com.caucho.network.listen.SocketLinkThreadLauncher.handleTasks(SocketLinkThreadLauncher.java:169)
    at com.caucho.network.listen.TcpSocketAcceptThread.run(TcpSocketAcceptThread.java:61)
    at com.caucho.env.thread2.ResinThread2.runTasks(ResinThread2.java:173)
    at com.caucho.env.thread2.ResinThread2.run(ResinThread2.java:118)
    

    欢迎任何想法/解决方案!

  • 共有1个答案

    江瀚昂
    2023-03-14

    Resin/Spring/Oracle/XA事务组合工作得很好。这里的关键是正确使用DB连接。

    必须在事务中打开所有DB连接。在这种情况下,该资源将隐式地为事务登记。我们的示例代码就是这样做的。

    问题是我们在启动新事务时保留了数据库连接。这意味着在开始新事务之前,Resin的db池提供的db连接(又名UserConnection)没有返回到池中。出于某种原因,Resin TransactionManager实现隐式地将未返回的db连接添加到内部事务中使用的资源列表中。内部事务的提交失败,因为Oracle知道外部未提交的事务中已经使用了db连接。

    public void doOuterTransaction() throws Throwable {
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setName("myTx");
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES);
        TransactionStatus status = txManager.getTransaction(def);
        Connection connection = null;
        Cache cache = null;
        try {
            try {
                cache = ...; // get cache from CacheManager
                connection = DataSourceUtils.getConnection(myDataSource);
                // some business logic
            } finally {
                DataSourceUtils.releaseConnection(connection, myDataSource);
            }
    
            doInnerTransaction();
    
            try {
                cache = ...; // get cache from CacheManager
                connection = DataSourceUtils.getConnection(myDataSource);
                // some other business logic 
            } finally {
                DataSourceUtils.releaseConnection(connection, myDataSource);
            }
        } catch (Throwable ex) {
            txManager.rollback(status);
            throw ex;
        }
    
        txManager.commit(status);
    }
    

    谢谢大家的帮助!

     类似资料:
    • 我有办法: 和每个内部事务的另一个bean: 当我第一次尝试保存时,我有20行DB。每次下一次保存,我得到+10行。名称具有约束。当我得到错误时,事务是提交而不是继续。每次保存后我都会等待98行。

    • 我在我的项目中做过类似的事情。我手动回滚事务,为此我插入了try-catch块并手动回滚catch块中的事务。现在我从method1调用method2,并将对象保存到method2()中的数据库中,但它不会将对象保存到数据库中。 我只是想知道什么是可能的解决方案,保存对象在方法2()在方法1()的faliure。 提前感谢。

    • 在以下代码方法中,更新正确的sql,但sql有一些问题,但是,当我调用doService()时,它必须将更新提交到DB,即使doService 2()有sql异常,因为doService 2()有一个新的传播类型,但是当我取消这个更新时,不会提交DB。。 正如你们的建议,以以下方式进行测试,但仍然面临相同的问题。这里i在一个单独的类中,但即使仍然存在与上述相同的问题

    • 问题内容: 我需要从存储过程中写入日志表。现在,此日志信息必须能够在回滚过程中幸免。 我知道以前曾问过这个问题,但是我的情况有所不同,在这些问题中找不到我的问题的答案。 当存储过程中没有错误时,事情就很简单了,日志表中的条目就在那里。 当有错误时,事情就变得复杂了。 在该过程中,我可以在catch中进行回滚,然后将数据插入日志表,我知道并且我已经在这样做了。 但是问题是当存储过程这样调用时: 我知

    • 我的路线如下 我知道(A)处的JMS消费者将在每次轮询时分叉JMS事务,并附加到线程。(B)中的事务处理节点也将在交换到达那里并连接到线程后分叉JPA事务。 请在下面找到我的问题: > < li >能否将两个不同的事务附加到一个线程上(如上所示)? < li >如果是,哪一个应该被停职? < li> 上述路由的提交和回滚顺序应该是什么? 注:我没有从骆驼在行动第二版中找到任何明显的答案,所以请指导

    • 支持项 支持数据分片后的跨库事务; 两阶段提交保证操作的原子性和数据的强一致性; 服务宕机重启后,提交/回滚中的事务可自动恢复; 支持同时使用 XA 和非 XA 的连接池。 不支持项 服务宕机后,在其它机器上恢复提交/回滚中的数据。