Discussions

EJB programming & troubleshooting: nested vs flat transactions

  1. nested vs flat transactions (2 messages)

    I have a trivial doubt:

    If EJB specifications is not supporting nested Transactions, how come the container is manging 'requires new' transactions?

    Correct me If I'm wrong:

    Case1:
      method1 of EJB1: Trans Att - "Requires"
      {
               db operations
               ......
               ......
               method2 of other EJB2
               ....
               ....
      }
      
      method2 of EJB2 : Trans Att - "Requires New"
      {
           DB operations.
           .......
           .......
      }

    Case 2:

        method1 of EJB1{
           Trans1.begin
                 DB opeartions....
                 method2()
                 .....
           Trans1.end
        }
        method2 of EJB2 ()
        {
           Trans2.begin
              Db operation......
              ....
           Trans2.end
        }

    Case1:
          From literature, I understood that, container suspends the existing transaction(if present) and run the method2() in a new transaction which is independent of the first transaction.

    Case2: Being termed as nested transaction.

    But, I didn't see any diff between two and one. If container is able to suspend some transaction, why can't a developer do the same programmatically?

    This has been a burning issue in my mind.
    Please clarify me,

    Thanks

    Threaded Messages (2)

  2. nested vs flat transactions[ Go to top ]

    In case of nested transactions,if inner transactions fail, the outer ones are automatically rolled back.

    This is not mandatory in your 'case 1' where the stipulation is that method 2 executes in a new transaction always.Method 2's transaction does not know,nor care about the scope of other transactions which may have invoked method 2.

    Also,method 1's transaction does not need to rollback(unless you code it to) even of method 2's transaction fails.

    Hope this clarifies your doubt.
  3. nested vs flat transactions[ Go to top ]

    Thank you for your information....It helped me.