I have no idea how to control Transaction-Boundary in EJB, can any people make suggestions.
i made a session-bean to trasfer account,
in this session-bean called some entitybean ,
but i'm afraid the instance of session bean is not unique,
so there can be some simultaneous access to the session-bean , maybe error.
the code is show blow:
/**
* transfer money from one account to another
* return value:
* 0: success
* ^0: failed, error code
*
* error code:
* 1: account not exists
* 2: not enought money in source account
*/
public int transAccount(String accountFrom, String accountTo, double transSum ){
AcaccounttbClient cFrom = new AcaccounttbClient();
AcaccounttbClient cTo = new AcaccounttbClient();
Acaccounttb acTbFrom = cFrom.findByPrimaryKey(accountFrom);
Acaccounttb acTbTo = cTo.findByPrimaryKey(accountTo);
if ( acTbFrom == null || acTbTo == null ){
return 1;
}
Double restSum = cFrom.getAccountsum();
if ( restSum.doubleValue() < transSum ){
return 2;
}
cFrom.setAccountsum(new Double(restSum.doubleValue()-transSum));
cTo.setAccountsum(new Double(cTo.getAccountsum().doubleValue()+transSum));
return 0;
}
(the code is well-formated, but looks urgly cause of the web page, u can copy it to another editor to see)
can this code cause trouble ?
so I guess if we can control the transactoin-boundary ,
(where the transaction begin and where the transaction end)
everything will be ok.
thanks
-
to control Transaction-Boundary in EJB (8 messages)
- Posted by: Blue Hand
- Posted on: July 02 2001 22:40 EDT
Threaded Messages (8)
- to control Transaction-Boundary in EJB by zhicheng ge on July 03 2001 01:17 EDT
- to control Transaction-Boundary in EJB by Blue Hand on July 03 2001 02:12 EDT
-
to control Transaction-Boundary in EJB by zhicheng ge on July 03 2001 09:38 EDT
-
to control Transaction-Boundary in EJB by One Way on June 29 2002 09:04 EDT
-
to control Transaction-Boundary in EJB by One Way on June 29 2002 09:06 EDT
-
to control Transaction-Boundary in EJB by One Way on June 29 2002 09:06 EDT
-
to control Transaction-Boundary in EJB by One Way on June 29 2002 09:07 EDT
- to control Transaction-Boundary in EJB by One Way on June 29 2002 09:07 EDT
-
to control Transaction-Boundary in EJB by One Way on June 29 2002 09:07 EDT
-
to control Transaction-Boundary in EJB by One Way on June 29 2002 09:06 EDT
-
to control Transaction-Boundary in EJB by One Way on June 29 2002 09:06 EDT
-
to control Transaction-Boundary in EJB by One Way on June 29 2002 09:04 EDT
-
to control Transaction-Boundary in EJB by zhicheng ge on July 03 2001 09:38 EDT
- to control Transaction-Boundary in EJB by Blue Hand on July 03 2001 02:12 EDT
-
to control Transaction-Boundary in EJB[ Go to top ]
- Posted by: zhicheng ge
- Posted on: July 03 2001 01:17 EDT
- in response to Blue Hand
You can set method's transaction atttribute to control the transation-boundary. For your example, you can set the transaction atttriubte of method transAccount(..) to tx_required.
-
to control Transaction-Boundary in EJB[ Go to top ]
- Posted by: Blue Hand
- Posted on: July 03 2001 02:12 EDT
- in response to zhicheng ge
do u mean I specify "container transaction" for this bean like below :
<container-transaction>
<method>
<ejb-name>AccountBean</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
that's enough ? now all method of my session-bean can be one seperate transaction ? M i right ? -
to control Transaction-Boundary in EJB[ Go to top ]
- Posted by: zhicheng ge
- Posted on: July 03 2001 21:38 EDT
- in response to Blue Hand
NOT all method of my session-bean can be one seperate transaction, but each method of your session bean will be running in a seperate transaction.
You should also set the referenced session bean's(or entity bean) method to tx_required. So that they can join in your session bean's transaction. -
to control Transaction-Boundary in EJB[ Go to top ]
- Posted by: One Way
- Posted on: June 29 2002 21:04 EDT
- in response to zhicheng ge
“The test’s test. Let’s see …” -
to control Transaction-Boundary in EJB[ Go to top ]
- Posted by: One Way
- Posted on: June 29 2002 21:06 EDT
- in response to One Way
“The test’s test. Let’s see … Please ignore …” -
to control Transaction-Boundary in EJB[ Go to top ]
- Posted by: One Way
- Posted on: June 29 2002 21:06 EDT
- in response to One Way
“The test’s test. Let’s see … Please ignore …” -
to control Transaction-Boundary in EJB[ Go to top ]
- Posted by: One Way
- Posted on: June 29 2002 21:07 EDT
- in response to One Way
“The test’s test. Let’s see … Please ignore …” -
to control Transaction-Boundary in EJB[ Go to top ]
- Posted by: One Way
- Posted on: June 29 2002 21:07 EDT
- in response to One Way
“The test’s test. Let’s see … Please ignore …”