Search code examples
javadatabaseoraclewebspheredatasource

Resource DATASOURCE rolled back in cleanup of LocalTransactionContainment


Im working in a WebSphere Application Server 7, JDK 1.6 and Oracle 11g.

Im always receiving this error when using an ejb.

[7/1/10 17:12:28:770 BOT] 00000013 LocalTranCoor W WLTC0033W: Resource jdbc/oraDS11 rolled back in cleanup of LocalTransactionContainment. [7/1/10 17:12:28:773 BOT] 00000013 LocalTranCoor W WLTC0032W: One or more local transaction resources were rolled back during the cleanup of a LocalTransactionContainment.

This is how im getting the connection from the datasource in WAS.

javax.sql.DataSource ds = (javax.sql.DataSource) naming.lookup("DataSource");
conn= ds.getConnection();

Any help will be appreciated...


Solution

  • From the error message, you are doing some work inside a local transaction and not committing it. The uncommitted work gets rolledback by the container at the end of the method (by default).

    This answer to Datasource rollback in WAS6.0 summarizes all this pretty well and since there is no real point at paraphrasing it, I'm quoting it below.

    A LocalTransactionContainment is what you get in the absence of a global (XA) transaction. The message indicates that you performed some local transaction work as part of that containment scope (method or activity session) and then did not commit. The default behaviour (controlled by unresolved-action) is to rollback any uncommited work at the end of the scope. You have a number of options:

    • Explicitly commit the local transaction

      connection.commit(); // after the work has been performed
      
    • Change the data source to use auto-commit

      connection.setAutoCommit(true); //
      

      before the connection is used

    • Place the work within a global transaction

      Context ic = new InitialContext();
      UserTransaction ut =
      (UserTransaction) ic.lookup("java:comp/UserTransaction");
      ut.begin();
      // use connection here
      ut.commit();
      
    • Change the unresolved-action to commit
      Select the 'Servlets' tab on the deployment descriptor editor and then select the servlet in question. Under 'WebSphere Extensions' and then 'Local Transaction' set the 'Unresolved Action' to 'Commit' from the drop-down menu.

    I'd suggest committing the work explicitly (and reading the whole answer).