Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

SessionSynchronization interface

 
Ranch Hand
Posts: 10191
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Why do we need to (optionally) implement SessionSynchronization interface for Stateful Session beans?
 
Ranch Hand
Posts: 560
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should rephrase your question:
the "need" and "optionally" words don't go well together.
Anyways, here's your answer:


A stateful session bean class can optionally implement the javax.ejb.SessionSynchronization
interface. This interface provides the session bean instances with transaction synchronization
notifications. The instances can use these notifications, for example, to manage database data they may
cache within transactions´┐Że.g., if the Java Persistence API is not used.

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jothi,

Some times you write a stateful Session Bean which does some database operations like.. Insert update and delete and for these operations you have written some methods in your bean class say.. goInsert(), goUpdate(),goDelete().

Since it is stateful session bean for your business logic you'll declare some instance variables in your class and those are nothing but the database fields, values of which you are going to take as parameters of these methods (goInsert,goUpdate,goDelete). It may have one more method called getData(id) which selects the data populates it inside the bean variables.

For this bean container is managing the transaction.

Consider that For the first time when client wants do to some processing it selects the data. so it calls getData(id), all the variables will be populated with data from database. Data has given to client through some DTO. Client modifies that data and calls ....

... goUpdate by passing changed values to it.. the container first will start a new transaction then it'll invoke the method. After the method call container is going to commit.

During this method invocation suppose you've updated few values in database and something goes wrong at runtime and exception occurs... so what will happen to the data inside the database and to the values of instance variables

to handle such situations... the bean has to implement SessionSynchronization interface where some callbacks will get called before start of Tx after end of Tx etc...

just correlate this example after applying SessionSynchronization and follow the specs

I hope this will clear your doubt.


Cheers..

bye



nitin
 
Celinio Fernandes
Ranch Hand
Posts: 560
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only stateful session beans with container managed transaction demarcation can implement this interface.
Session beans using BMT must not implement SessionSynchronization.
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!