If Method M1 is invoked by a method that does NOT have a transaction context, which describes a possible scenario?

Given a set of CMT bean methods with the following transaction attributes:
Method M1 = SUPPORTS
Method M2 = REQUIRED
Method M3 = NOT_SUPPORTED
Method M4 = REQUIRES_NEW

And the following method invocation sequence:
Method M1 invokes Method M2
Method M2 invokes Method M3
Method M1 invokes Method M4
If Method M1 is invoked by a method that does NOT have a transaction context, which describes a possible scenario?

Given a set of CMT bean methods with the following transaction attributes:
Method M1 = SUPPORTS
Method M2 = REQUIRED
Method M3 = NOT_SUPPORTED
Method M4 = REQUIRES_NEW

And the following method invocation sequence:
Method M1 invokes Method M2
Method M2 invokes Method M3
Method M1 invokes Method M4
If Method M1 is invoked by a method that does NOT have a transaction context, which describes a possible scenario?

A.
Method M1 : no transaction
Method M2 : new transaction
Method M3 : no transaction
Method M4 : new transaction

B.
Method M1 : no transaction
Method M2 : Container throws TransactionNotSupportedException

C.
Method M1 : no transaction
Method M2 : runs in same transaction as M1
Method M3 : container throws TransactionNotSupportException

D.
Method M1 : no transaction
Method M2 : new transaction
Method M3: Container throws TransactionNotSupportException.



Leave a Reply 6

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


Albert Fröhlich

Albert Fröhlich

A, i implemented it in jboss 8.1, all methods finished normal

Tommy_Croatia_ZGB

Tommy_Croatia_ZGB

A is the correct answer.

Transaction Attribute | Client’s Transaction | Business Method’s Transaction
Required | None | T2
Required | T1 | T1
RequiresNew | None | T2
RequiresNew | T1 | T2
Mandatory | None | Error (TransactionRequiredException)
Mandatory | T1 | T1
NotSupported | None | None
NotSupported | T1 | None
Supports | None | None
Supports | T1 | T1
Never | None | None
Never | T1 | Error (RemoteException)

A transaction attribute can have one of the following values:

1. Required
2. RequiresNew
3. Mandatory
4. NotSupported
5. Supports
6. Never

1. Required Attribute
If the client is running within a transaction and invokes the enterprise bean’s method, the method executes within the client’s transaction. If the client is not associated with a transaction, the container starts a new transaction before running the method.

The Required attribute is the implicit transaction attribute for all enterprise bean methods running with container-managed transaction demarcation. You typically do not set the Required attribute unless you need to override another transaction attribute. Because transaction attributes are declarative, you can easily change them later.

2. RequiresNew Attribute
If the client is running within a transaction and invokes the enterprise bean’s method, the container takes the following steps:

Suspends the client’s transaction

Starts a new transaction

Delegates the call to the method

Resumes the client’s transaction after the method completes

If the client is not associated with a transaction, the container starts a new transaction before running the method.

You should use the RequiresNew attribute when you want to ensure that the method always runs within a new transaction.

3. Mandatory Attribute
If the client is running within a transaction and invokes the enterprise bean’s method, the method executes within the client’s transaction. If the client is not associated with a transaction, the container throws a TransactionRequiredException.

Use the Mandatory attribute if the enterprise bean’s method must use the transaction of the client.

4. NotSupported Attribute
If the client is running within a transaction and invokes the enterprise bean’s method, the container suspends the client’s transaction before invoking the method. After the method has completed, the container resumes the client’s transaction.

If the client is not associated with a transaction, the container does not start a new transaction before running the method.

Use the NotSupported attribute for methods that don’t need transactions. Because transactions involve overhead, this attribute may improve performance.

5. Supports Attribute
If the client is running within a transaction and invokes the enterprise bean’s method, the method executes within the client’s transaction. If the client is not associated with a transaction, the container does not start a new transaction before running the method.

Because the transactional behavior of the method may vary, you should use the Supports attribute with caution.

6. Never Attribute
If the client is running within a transaction and invokes the enterprise bean’s method, the container throws a RemoteException. If the client is not associated with a transaction, the container does not start a new transaction before running the method.