Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stateful Session Bean Implementation

 
Prajakta Acharya
Ranch Hand
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Prajakta Acharya
Ranch Hand
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any one has any idea regarding this? Is my understanding right?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic