Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Query on Transaction Context of Session Bean Methods

 
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Creator of Enthuware JWS+ V6
Posts: 3345
303
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3345
303
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Frits
 
I was born with webbed fish toes. This tiny ad is my only friend:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic