cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Something about Container-Managed Transaction

Former Member
0 Kudos

Although I had already read the information about Container-Managed transaction, I still have some confuse on the Transaction Type : MANDATORY and REQUIRED

My situation is :

I am using the NW CE7.1 to implement the CAF

in the application service, I have implement a create operation as follow:

-


@javax.ejb.TransactionAttribute (javax.ejb.TransactionAttributeType.XXXXXXXX)

public <CustomerCreationRequest> create{

CustomerCreationRequestServiceLocal cs = this.getCustomerCreationRequestService();

//create customer

CustomerCreationRequest ccq = cs.create();

if(true){

throw new CAFCreateException();

}

}

public abstract class CustomerCreationRequestBean implements

CustomerCreationRequestServiceLocal {

@TransactionAttribute (TransactionAttributeType.REQUIRED)

public CustomerCreationRequest create

{

try{

// do create

}catch(DataAccessException _e) {

sessionContext.setRollbackOnly();

}

}

}

-


In the above method, an exception is thrown so that I can observe the behaviour of different transcation type

if the type is set to REQUIRED,

the transcation will not rollback, thus customer created

but if the type is set to MANDATORY

the transcation will rollback and no customer is created

as a result, these outcomes confuse me,

since I will guess that both transcation will be rollback.

So could anyone give me some explanation on the above situation. As I expcected no matter it is REQUIRED or MANDATORY, it should be execute in the same transcation context. But the result shows me they are in different transcation

really thanks in advance

DAVID

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi David

REQUIERED means that the client can invoke the EJB method within or without a transactions context. If the client invokes the enterprise beanu2019s method while the client is not associated with a transaction context, the container automatically starts a new transaction.

MANDATORY means that the client is required to call with a transaction context. If the client calls whitout a transaction context the container must throw the javax.ebj.EJBTransactionRequiredException.