on 06-03-2008 8:44 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.