Under which of these conditions could this be possible?

A stateless session bean’s business method invokes EJBContext.setRollBackOnly and receives an IllegalStateException.
Under which of these conditions could this be possible?

A stateless session bean’s business method invokes EJBContext.setRollBackOnly and receives an IllegalStateException.
Under which of these conditions could this be possible?

A.
The business method is marked with the MANDATORY transaction attribute.

B.
The business method is marked with the NONSUPPORTED transaction attribute.

C.
This Is NOT possible; a stateless session bean cannot invoke EJBContext.SetRollBackOnly.

D.
The bean has no metadata (in annotations 01 deployment descriptor) which specifies the
transaction attribute for the method.



Leave a Reply 2

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


Mohamed Fayek

Mohamed Fayek

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).

Mohamed Fayek

Mohamed Fayek

answer :B

he Container must throw the java.lang.IllegalStateException if the EJBContext.setRollbackOnly() method is invoked from a business method executing with the Supports, NotSupported, or Never (for MDB – ONLY with NotSupported) transaction attribute. ?

The transaction attributes Supports, NotSupported and Never do not require a transaction. Therefore, it seems reasonable to me that the invocation of any EJBContext method such as setRollbackOnly() must be regarded as illegal when the method is marked with any of these attributes and will result in java.lang.IllegalStateException being thrown by the container.

Note: Bean’s business method with NotSupported attribute, will always be executed in unspecified transaction context.