Home » Interview Questions » EJB Interview Questions » What are transactional attributes?
 

What are transactional attributes?

EJB transactions are a set of mechanisms and concepts, which insures the integrity and consistency of the database when multiple clients try to read/update the database simultaneously.

Transaction attributes are defined at different levels like EJB (or class), a method within a class or segment of a code within a method. The attributes specified for a particular method take precedence over the attributes specified for a particular EJB (or class). Transaction attributes are specified declaratively through EJB deployment descriptors. Unless there is any compelling reason, the declarative approach is recommended over programmatic approach where all the transactions are handled programmatically. With the declarative approach, the EJB container will handle the transactions.

Required: Methods executed within a transaction. If client provides a transaction, it is used. If not, a new transaction is
generated. Commit at end of method that started the transaction. Which means a method that has Required
attribute set, but was called when the transaction has already started will not commit at the method
completion. Well suited for EJB session beans.

Mandatory: Client of this EJB must create a transaction in which this method operates, otherwise an error will be
reported. Well-suited for entity beans.

RequiresNew: Methods executed within a transaction. If client provides a transaction, it is suspended. If not a new
transaction is generated, regardless. Commit at end of method.

Supports: Transactions are optional.

NotSupported: Transactions are not supported. If provided, ignored.

Never: Code in the EJB responsible for explicit transaction control.



Write a comment

  • Required fields are marked with *.

If you have trouble reading the code, click on the code itself to generate a new random code.
Security Code: