Java Transaction API (JTA) - Interview Questions

What are transactions in Java EE Application?

 FAQ

Transactions in Java EE application are a series of actions that all must be completed successfully, or else the changes in each action are backed out. If all the actions are successful then the changes from all actions are committed. If any one of the actions is unsuccessful then the changes from all the actions are rolled back.

What is JTA (Java Transaction API) in Java EE?

 FAQ

Java Transaction API is an API specified in Java EE that provides applications a standard way to access transactions independent of any specific implementation. JTA transactions are controlled by Java EE transaction manager. Transaction are started, committed or rolled back by calling corresponding methods on the UserTransaction API.

How are transactions maintained in an EJB application?

 FAQ

Transactions in EJB application are either Container-Managed or Bean-Managed

Container-Managed Transactions - In Container-Managed transactions the transaction boundaries are set in the EJB container. Container-managed transactions can be set for both session beans as well as message-driven beans.

Bean-Managed Transactions - In Bean-Managed transactions the transaction boundaries are set specifically within the bean's code. Bean managed transactions can be set for session beans as well as message-driven beans. Bean manages transaction can either use JDBC transactions or JTA transactions.

What are transaction attributes in Container-Managed transactions?

 FAQ

Transaction attribute determines the scope of a transaction across beans. For example, if methodA() of Bean A starts a transaction and calls methodB() of bean b, then does methodB() run within the transaction started by methodA()? This is determined by the transaction attribute set on methodB()

A transaction attribute can have one of the following values -

1. Required

2. RequiresNew

3. Mandatory

4. NotSupported

5. Supports

6. Never

What is 'Required' transaction attribute that can be defined in Container-Managed transactions?

 FAQ

If a client has an associated transaction and calls a container-managed bean's method then the method executes within the client transaction.

If the client is not associated with a transaction then the container starts a new transaction before calling the bean's method.

What is 'RequiresNew' transaction attribute that can be defined in Container-Managed transactions?

 FAQ

If a client has an associated transaction and calls a container-managed bean's method then the container suspends the clients transaction, starts a new transaction, starts the call to the method and starts the clients transaction after method completes.

If the client is not associated with a transaction then the container starts a new transaction before calling the beans method.

What is 'Mandatory' transaction attribute that can be defined in Container-Managed transactions?

 FAQ

If a client has an associated transaction and calls a container-managed bean's method then the method executes within the client transaction.

If a client is not associated with a transaction then the container throws a TransactionRequiredException

What is 'NotSupported' transaction attribute that can be defined in Container-Managed transactions?

 FAQ

If a client has an associated transaction and calls a container-managed bean's method then the container suspends the clients transaction, calls the bean's method, and starts the clients transaction after method execution completes.

If a client is not associated with a transaction, then the container does not start a new transaction before calling the bean's method.

What is 'Supports' transaction attribute that can be defined in Container-Managed transactions?

 FAQ

If a client has an associated transaction and calls a container-managed bean's method then the method executes within the client transaction.

If a client is not associated with a transaction, then the container does not start a new transaction before calling the bean's method.

What is the Never transaction attribute that can be defined in Container-Managed transactions?

 FAQ

If a client has an associated transaction and calls a container-managed bean's method then the container throws a RemoteException.

If a client is not associated with a transaction, then the container does not start a new transaction before calling the bean's method.

How do you set transaction timeouts in container-managed and bean-managed transactions?

 FAQ

Container-Managed Transaction - In container managed transactions the transaction timeout is set at the container's administration console.

Bean-Managed Transactions - In Bean-managed transactions, the transaction timeout is set by calling the setTransactionTimeout() method of the UserTransaction interface.

 
Subscribe to our Questions

 

Java EE - Interview Questions

Java ServletsJavaServer PagesJavaServer FacesJava API for XML Processing (JAXP)Java API for JSON Processing (JSON-P)Java Message Service API (JMS)Java Persistance API (JPA)Java Transaction API (JTA)JAX-WSJava API for RESTful Web Services (JAX-RS)Java Database Connectivity API (JDBC)Security
 
RECOMMENDED RESOURCES
Behaviorial Interview
Top resource to prepare for behaviorial and situational interview questions.

STAR Interview Example