资源DATASOURCE在LocalTransactionContainment的清理中回滚

Gar*_*ero 4 java database oracle websphere datasource

我在WebSphere Application Server 7,JDK 1.6和Oracle 11g中工作.

我总是在使用ejb时收到此错误.

[7/1/10 17:12:28:770 BOT] 00000013 LocalTranCoor W WLTC0033W:资源jdbc/oraDS11在LocalTransactionContainment的清理中回滚.[7/1/10 17:12:28:773 BOT] 00000013 LocalTranCoor W WLTC0032W:在清理LocalTransactionContainment期间回滚了一个或多个本地事务资源.

这就是我如何从WAS中的数据源获取连接.

javax.sql.DataSource ds = (javax.sql.DataSource) naming.lookup("DataSource");
conn= ds.getConnection();
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激...

Pas*_*ent 6

从错误消息中,您正在本地事务中执行一些工作而不是提交它.未提交的工作在方法结束时由容器回滚(默认情况下).

这个对WAS6.0中数据源回滚的回答总结了所有这些,并且由于没有真正意义上的解释,我在下面引用它.

A LocalTransactionContainment是在没有全局(XA)事务的情况下获得的.该消息表明您执行了一些本地事务工作作为该包含范围(方法或活动会话)的一部分,然后未提交.默认行为(由unresolved-action控制)是在作用域末尾回滚任何未通信的工作.你有很多选择:

  • 显式提交本地事务

    connection.commit(); // after the work has been performed
    
    Run Code Online (Sandbox Code Playgroud)
  • 更改数据源以使用自动提交

    connection.setAutoCommit(true); //
    
    Run Code Online (Sandbox Code Playgroud)

    在使用连接之前

  • 将工作放在全局事务中

    Context ic = new InitialContext();
    UserTransaction ut =
    (UserTransaction) ic.lookup("java:comp/UserTransaction");
    ut.begin();
    // use connection here
    ut.commit();
    
    Run Code Online (Sandbox Code Playgroud)
  • 将unresolved-action更改为commit
    在部署描述符编辑器中选择"Servlets"选项卡,然后选择相关的servlet.在"WebSphere Extensions"下,然后在"Local Transaction"下,从下拉菜单中将"Unresolved Action"设置为"Commit".

我建议明确地提交工作(并阅读整个答案).