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.
A
A is correct.
Reference:
http://docs.oracle.com/javaee/6/api/javax/ejb/EJBContext.html#setRollbackOnly%28%29
A
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).
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.
I think none of the answers are correct. UserTransaction.setRollbackOnly throws that exception because there is no active transaction.