Search code examples
transactionsejbcontainer-managedbean-managed-transactions

Some CMT and BMT doubts in EJB?


when using CMT in session beans where do we commit the transaction?

With REQUIRES_NEW attribute Container creates a new transaction and the callers transaction is suspended Just get better understanding of REQUIRES_NEW , does it achieve the above behaviour by associating transaction with new connection. Once complete the current transaction it assume the previous connection? when the commit happens for new transaction?

Can somebody point me the brief eamxple CMT and BMT where sesion bean using JDBC. Basically looking how we get the connection,commit, rollback in CMT and BMT

In CMT, Transaction manager Complete the transaction associated with the current thread. My question here is how does it commit the transaction . I know of commiting the transaction with connection but here how does it the get to know which connection associated with current thread as in one example i saw of creation the connection inside the method with new operator.


Solution

  • when using CMT in session beans where do we commit the transaction?

    When the method that started the transaction ends, assuming it did not end with a system exception.

    does it achieve the above behaviour by associating transaction with new connection.

    Connections aren't shared across transactions. Each connection becomes bound to the transaction in which it was obtained.

    Can somebody point me the brief eamxple CMT and BMT where sesion bean using JDBC. Basically looking how we get the connection,commit, rollback in CMT and BMT

    You should get/use/close all within the same transaction.

    I know of commiting the transaction with connection but here how does it the get to know which connection associated with current thread as in one example i saw of creation the connection inside the method with new operator.

    When you obtain a connection, the container enlists the resource with the current transaction. The transaction manager while drive callbacks to the XAResource when the transaction commits or rolls back.