• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SessionSynchronization Clarification

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Under what situation do we want to use SessionSynchronization to get notification of transaction status? Many books says we load data from db in afterBegin() & write the changes in beforeCompletion(). But it is difficult for me to imagine the situation we want to do this. It seems that it is applicable only when we spread the transaction across many methods? Am I correct?

If I have a CMT SFSB where every method starts a new txn and complete it b4 returning, how do we use the SessionSynchronization methods ?

Appreciate anyone can share a real life situation they encountered that really need to use SessionSynchronization bean in the design.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this article, BEA folks share some experience on the use of the SessionSynchronization interface.


[...]
the typical use case of the SessionSynchronization interface is a stateful session bean with its beforeCompletion method containing an implementation that flushes any state that may have been cached before the commit processing begins (of course, if state is cached when the transaction is committed, then it will never be written to the back-end storage). The afterCompletion implementation, when the final result is a JTA rollback, will likely return the session state to some values saved prior to its commencement.
[...]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic