• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stateful Session Bean Implementation

 
Ranch Hand
Posts: 138
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any one has any idea regarding this? Is my understanding right?
 
reply
    Bookmark Topic Watch Topic
  • New Topic