aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Stateful Session Bean Implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Stateful Session Bean Implementation" Watch "Stateful Session Bean Implementation" New topic
Author

Stateful Session Bean Implementation

Prajakta Acharya
Ranch Hand

Joined: Nov 08, 2012
Posts: 138

Hi All,

I am trying to test creation of a stateful session bean to validate my understanding.
To my surprise, the bean is getting instantiated twice in the same session, so I am confused.

This is what I have done:
1) Declared a stateful session bean as follows:


2) Created a ServiceLocator class to look-up EJB components.

3) Invoked look-up method of ServiceLocator from servlet to get required stateful session bean.

4) I am looking up the same bean in two servlets. These servlets are invoked in a single session.

I expected that only one session bean be returned in both the servlets, but the bean's constructor is called 2 times.

Any pointers would be very much helpful.

Thanks.



Regards,
Prajakta
Prajakta Acharya
Ranch Hand

Joined: Nov 08, 2012
Posts: 138

Posting complete code.
=================
Sequence:
1) Index page accepts user name and invokes AuctionServlet.
2) Servlet looks up the stateful session bean with ServiceLocator. It sets 'User' instance variable of this session bean (with entered user name).
3) User redirected to another JSP informing that registration is successful and asked to click next.
4) On click of next, AuctionUserServlet is invoked.
5) AuctionUserServlet looks up the same session bean and displays the logged in user's name by accessing the User instance variable ---------- Getting null user here.....

Code below:
===================

AuctionServlet


ServiceLocator


AuctionUserServlet


Stateful session bean
Prajakta Acharya
Ranch Hand

Joined: Nov 08, 2012
Posts: 138

Any one has any idea regarding this? Is my understanding right?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stateful Session Bean Implementation