File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Query on Transaction Context of Session Bean Methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Query on Transaction Context of Session Bean Methods" Watch "Query on Transaction Context of Session Bean Methods" New topic
Author

Query on Transaction Context of Session Bean Methods

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

Source:EJB 3.1 specification



4.3.15 Transaction Context of Session Bean Methods

The implementation of a method defined in a session bean’s business interface or component interface
or no-interface view, a web service method, timeout callback method, or singleton PostCon-
struct/PreDestroy lifecycle callback interceptor method, is invoked in the scope of a transaction
determined by the transaction attribute specified in the bean’s metadata annotations or deployment
descriptor.
A session bean’s afterBegin and beforeCompletion methods are always called with the same
transaction context as the business methods executed between the afterBegin and beforeCom-
pletion methods.
A session bean’s newInstance, setSessionContext, other dependency injection methods, life
cycle callback interceptor methods, and afterCompletion methods are called with an unspecified
transaction context


Below is my understanding for the text provided above.Please let me know if the understanding below is correct.If not,please point me in the right direction:

As far i understand,suppose a client executes a method getAddressDetails on a statefull bean Address,then Transaction will be client requesting address details and as it said above

"A session bean’s afterBegin and beforeCompletion methods are always called with the same
transaction context as the business methods executed between the afterBegin and beforeCom-
pletion methods
."

Then,afterBegin and beforeCompletion are always executed as a part of client request(here,getAddressDetails).
They cannot be changed using the transaction attribute specified in the bean’s metadata annotations or deployment descriptor.However,the other methods like "bean’s newInstance, setSessionContext, other dependency injection methods, life cycle callback interceptor methods, and after-completion methods can be changed to invoked in the scope of a transaction opposed to there default behavior.


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1734
    
  25

As far i understand,suppose a client executes a method getAddressDetails on a statefull bean Address,then Transaction will be client requesting address details and as it said above
Then,afterBegin and beforeCompletion are always executed as a part of client request(here,getAddressDetails).

No, the transaction context of the Session Bean's business method is determined by the TransactionAttribute metadata of the Session Bean in combination with the transaction being present (or absent) in the client. (my ScbcdLinks ch. 5.4.4). The afterBegin and beforeCompletion methods however will run in the same transaction context as the business methods of the particular Session bean.

Regards,
Frits
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

Hi Frits,

I think i have understood your point but still need your last confirmation on the below text:

Suppose getAddressDetails is the business method.Then,the afterBegin and beforeCompletion methods will always run in the same transaction context as the business method (here,getAddressDetails ).
afterBegin and beforeCompletion methods transaction context cannot be changed changed using the transaction attribute specified in the bean’s metadata annotations or deployment descriptor.

Please advise.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1734
    
  25

afterBegin and beforeCompletion methods transaction context cannot be changed using the transaction attribute specified in the bean's metadata annotations or deployment descriptor.

Yes, correct

Regards,
Frits
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

Thanks again Frits
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Query on Transaction Context of Session Bean Methods