GeeCON Prague 2014*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes SLSB & SessionSynchronization interface 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 "SLSB & SessionSynchronization interface" Watch "SLSB & SessionSynchronization interface" New topic
Author

SLSB & SessionSynchronization interface

Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222
Page 253, answer to the question 7 of the mock exam says that, "A Stateless session bean cannot implement the SessionSynchronization interface". I don't understand why it is like this? I know, spec also says the same. But, is there a logical reason associated with this?
Pravin Patunkar
Greenhorn

Joined: Jan 29, 2006
Posts: 2
Hi Ankit,
Consider scinario of any shopping cart. The obvious choice for it is stateful session bean. User adds item A in cart, then user adds item B in cart. But when user is trying to add item C into cart some run time exception occurs. The desired beahaviour for the application to restore the state to the cart with items A and B in it. This can be achieved with SessionSynchronization interface. Without this user need to start all over again.
This is not required for stateless session beans because, they do not hold user conversation state between method invocations. If we implement the above example with stateless beans then client always need to pass the current state information. Means as method parameter client will pass how many items it has in the cart. So even if transaction is rolled back while adding item C you still have A and B in virtual cart. As you do not have any user state there is no point in implementing SessionSynchronization interface.
Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222
Does that mean that the stateless session beans don't need transaction at all?
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Originally posted by Ankit Doshi:
Does that mean that the stateless session beans don't need transaction at all?


No, SessionSynchonization is for synchronizing purpose, hence stateless session bean don't need to implement it because stateless session bean don't have state. Furthurmore, for BMT stateful session bean you begin and commit transaction yourself therefore there is no need to use SessionSynchronization.

In conclusion only CMT stateful session bean may implement SessionSynchonization.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
vu lee
Ranch Hand

Joined: Apr 19, 2005
Posts: 189
Consider scinario of any shopping cart. The obvious choice for it is stateful session bean. User adds item A in cart, then user adds item B in cart. But when user is trying to add item C into cart some run time exception occurs. The desired beahaviour for the application to restore the state to the cart with items A and B in it. This can be achieved with SessionSynchronization interface. Without this user need to start all over again.


How could you restore the bean??? This is not an entity bean.
Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222
Originally posted by Kengkaj Sathianpantarit:


No, SessionSynchonization is for synchronizing purpose, hence stateless session bean don't need to implement it because stateless session bean don't have state.


Ok, I understand that since SessionSynchronization is mainly for synchronizing the state and since the SLSB doesn't maintain any state hence they don't need to implement the SessionSynchronization.

But I am still confusing on why would the SLSB need to manage transaction? Probably what I understand is that, transaction management is only important when the transaction has to span over multiple methods.

Can someone give me a example scenario wherein a problem would occur in case the SLSB is not associated with any transaction?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SLSB & SessionSynchronization interface