EJB programming & troubleshooting: EJB Container-Managed Transaction Creating Entity Bean

  1. I have a stateless session bean with container-managed transactions. In one of the business methods, the first
    thing I do is create an entity bean (bean-managed persistance). In trying to test the transaction mechanism, I immediately throw an EJBException to see that the entity bean create is rolled-back. In the server log, I can see that a rollback happened, but the entity data is indeed stored in the database.

    Can someone tell me when to start looking. I am using Weblogic 5.1 and have reviewed their documentation and the EJB spec and cannot find anything that explains this behavior.

    Thanks in advance for your help.
  2. hi Katherine,

      I faced the same problem many a times. But for me this happens only with first create call.
    (ofcourse I am also using wls5.1)

  3. Thanks for you input. It is nice to know others are having the same problem.

    Just wanted to let everyone know that I corrected the problem. JDBC has autoCommit set to true by default and thus you cannot rollback a transaction. Perhaps others are having the same problem. When I used conn.setAutoCommit(false) the rollback was successful.

  4. When I used conn.setAutoCommit(false) the rollback was successful.

       Katherine, that is indeed weird! You would think that the container would be smart enough to manage things like that. Perhaps there is some sort of deployment descriptor flag that needs to be set or something like that...

  5. That's weird, indeed.
    However, Katherine didn't mention if its bean was a CMP bean and, if it was, how she got the connection.
    If she correctly used the datasource/connection pool mechanism, or if the bean was CMP, then it's a bug (and an important one) in WLS.
    Else, if she used DriverManager.getConnection(), she probably bypassed the container mechanism, and got a connection with autocommit set to true.

  6. The entity bean has BMP and creates the connection using the DataSource method.

  7. The idea is very interesting. The Rollback works fine, if some exception happens. But after setAutoCommit(false) my data didn't store in DB. Server log showed, that transaction was well and commited by server.