Search code examples
transactionsejbtransactionaldistributed-transactions

In EJB how @TransactionAttribute(TransactionAttributeType.REQUIRED) will commit my jdbc transaction as well?


In EJB I have found that there is an annotation available like @TransactionAttribute(TransactionAttributeType.REQUIRED) , So transaction will be managed by container itself. But with use of it, you don't need to write con.commit() as Container will take care of it(Which I am just guessing as I am new in EJB). So my confusion is that how jdbc transaction gets associated with container Transaction that it get committed at the end of method having annotation @TransactionAttribute(TransactionAttributeType.REQUIRED)


Solution

  • The short answer is yes, unless an exception occurs in which case the transaction will be rolled back. This is a example of a Container Managed Transaction. The other option is User Managed Transaction, where the boundaries of the transactions are defined with tx.begin(), tx.commit() etc. For most needs Container Managed transactions are enough.