Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query on Transaction Context of Session Bean Methods

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE 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.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2264
76
Android Chrome Eclipse IDE
  • 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
Chrome Eclipse IDE 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
Saloon Keeper
Pie
Posts: 2264
76
Android Chrome Eclipse IDE
  • 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
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic