Container managed transactions not rolling back [Weblogic 5.1] !


EJB programming & troubleshooting: Container managed transactions not rolling back [Weblogic 5.1] !

  1. Hi there.

    I've been testing container managed transactions in a stateless session bean by invoking the following method from my client;

      public void insertToDb() {
          InitialContext ctx = null;
          try {
            ctx = new InitialContext();
            dataAccessSource = (javax.sql.DataSource) ctx.lookup ("securityDataSource");
            Connection con = dataAccessSource.getConnection();
            Statement stmt = con.createStatement();
            stmt.execute("INSERT INTO USERS (U_NAME,U_PASSWORD) VALUES ('xxx','yyy')");
            throw new EJBException("should rollback");
          } catch (Exception e) {

    The bean is deployed with the TX_REQUIRED transaction attribute and Container managed transactions. The data source is a TXDataSource type. However when invoked, no RemoteException is detected on the client, no rollback message is seen on the server console, and the database insert is not rolled back!!! Why is this happening?

    Furthermore, I'm using Weblogic Service Pack 8, which supposedly resolves this problem (Issue 37429).

    Many thanks

  2. Can you throw another EJBException in your catch block and see what happens?
  3. Hi,

    You cannot call the close() method on the connection object provided by the datasource connection pool. The DataSource object will take care of that. You should be OK once you remove the close() statement.

  4. Thanks for the suggestions guys, but neither of them solve the problem. Anyone else have any ideas?

  5. Is "securityDataSource" a TXDataSource specified in WLS 5.1's properties file or WLS 6.0's config.xml file?
  6. Yes it is.
  7. Now I am clueless. I did a quick test using your code and used a TXDataSource. The client is a Java console class that has no transaction context. When the insertToDb method TX attribute is set to Required, throwing an EJB exception and calling SessionContext.setRollbackOnly both rolled back the insert. However, when the TX attribute is set to Supports, neither resulted in a rollback.
  8. You've got me clueless too! What setup are you using?

    The stacktrace I'm getting on the server is

    javax.ejb.EJBException: should rollback
            at transactiontest.TransactionBean.insertToDb(
            at transactiontest.TransactionBeanEOImpl.insertToDb(TransactionBeanEOImp
            at transactiontest.TransactionBeanEOImpl_WLSkel.invoke(TransactionBeanEO
            at weblogic.rmi.extensions.BasicServerObjectAdapter.invoke(BasicServerOb
            at weblogic.rmi.extensions.BasicRequestHandler.handleRequest(BasicReques
            at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
    Tue Jan 30 14:07:36 GMT+00:00 2001:<I> <RJVM> Signaling peer -588471383774950314
    4C161.102.212.114 gone: weblogic.rjvm.PeerGoneException:
     - with nested exception:
    [ Connection reset by peer]

  9. Actually, I've solved the problem! And it's down to my own
    stupidity, I do apologize. The problem was I was not rethrowing the EJBException in the catch - as you asked me to do. When I rethrow it, the EJBException is reported to the client and the tx rolled back, and all is well.

    Thanks for your help!