Under which circumstance can this happen?

A session bean business method invokes UserTransaction.setRollbackonly and receives an IllegalStateException.
Under which circumstance can this happen?

A session bean business method invokes UserTransaction.setRollbackonly and receives an IllegalStateException.
Under which circumstance can this happen?

A.
The bean is using bean-managed transactions regardless of whether there is an active transaction.

B.
There is no circustance that would cause setRollbackOnly to throw an IllegalStateException.

C.
The bean is using bean managed transaction demarcation, and uaerTransaccion.begin has been invoked.

D.
The setRollbackOnly method is invoked within a bean-managed transaction, and userTransaction.commit has NOT been invoked.



Leave a Reply 6

Your email address will not be published. Required fields are marked *


Mohamed Fayek

Mohamed Fayek

A

setRollbackOnly

void setRollbackOnly()
throws java.lang.IllegalStateException
Mark the current transaction for rollback.

The transaction will become permanently marked for rollback. A transaction marked for rollback can never commit.

Only enterprise beans with container-managed transactions are allowed to use this method.

Throws:
IllegalStateException – The Container throws the exception if the instance is not allowed to use this method (i.e. the instance is of a bean with bean-managed transactions).

Tommy_Croatia_ZGB

Tommy_Croatia_ZGB

A is the correct answer, because IllegalStateException will be thrown in the case when current thread is not associated with the transaction. So if we try to call setRollbacOnly() method before the begining of the transaction, the exception will be thrown.

Description from the Oracle docs (http://docs.oracle.com/javaee/6/api/javax/transaction/UserTransaction.html):

setRollbackOnly method:

void setRollbackOnly() throws java.lang.IllegalStateException, SystemException

Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.

Throws:
IllegalStateException – Thrown if the current thread is not associated with a transaction.
SystemException – Thrown if the transaction manager encounters an unexpected error condition.

hmma

hmma

I think none of the answers are correct. UserTransaction.setRollbackOnly throws that exception because there is no active transaction.