Problem with transaction rollback in Entity EJB


EJB programming & troubleshooting: Problem with transaction rollback in Entity EJB

  1. Problem with transaction rollback in Entity EJB (5 messages)

    I am having some problems with transaction roll back involving Entity EJB's.

    I have a session bean method like,

    public void someMethod{
       // lookup for entity home
       // home.create();

       // Modify some other entity bean
       // At this point if we have some runtime exception,the whole trx should roll back.


    I have a trnsaction attribute of Required for someMethod. Also, create method has Supports trx attribute.

    All my create calls are getting commited even if transaction has rolled back. If I am updating some fields in Entity bean its getting rolled back perfectly fine.

    The problem is only with create calls.

    I am using Weblogic 6.1 sp2 server. I also looked at the Administrative console to monitor the transaction. Its showing that someMethod of session bean has bean rolled back. Also, its not showing create calls for Entity Bean in transaction log which is correct as create calls are part of transaction started by session bean "someMethod".This rules out the possibility that create calls are performed in separate trx.

    It seems that as server has to insert a record while doing a create, its not able to rollback due to some reason.

    Any pointers to the above problem are welcome.


  2. The spec gives the vendor the option to not roll the transaction back if the underlying data store remains consistent. Insertion does not compromise consistency. The vendors may choose not to rollback home.create() transactions.
  3. I found the problem with my Weblogic configuration. I had to use TX datasource.

    If a normal datasource is used instead of TX datasource, you will not see these transaction conflicts with Entity Bean updates, since server doesn't call ejbstore if the transaction is rolled back.

    But in ejbCreate of Entity Beans, server inserts a record in the table and since we are using a normal datasource, its committed immediately. Now even if transaction is rolled back, record is already there.

    You will face the same problem if you are using a SQL query in session Bean.

  4. I also have a similar problem
    1 stateless session bean , 2 BMP entity beans ( B1 & B2 ).
    Sessions bean business method has two inserts using B1 & B2.
    B1 inserted first via home.create..
    Then before B2's create an exception occurs..
    Unable to roll back the inserted data via B1.
    What is the solution for this. How to control the transaction..
    Need help. Any JTA enabled drivers you know..

  5. If there is a javax.ejb.CreateException or a java.sql.SQLException while doing a create or a insert query, it will not roll back your previous SQL insert.

    CreateException or SQLException is a type of Application Exception and you have to manually rollback the transaction using setRollBack Only() method or throwing a EJBException.

  6. Where is the solution?[ Go to top ]

    Does anyone really know how to make this work? It seems like such a simple thing to ask for. I cannot get my home.create() statements to roll back either. I need an answer badly. Can anyone help? I have a session bean that call an entity bean that creates another entity. This will never roll back. All other operations are rolled back and I am left with extra bogus records.

    I am using JBoss 4.0 + mysql.