my dog learned polymorphism*
The moose likes EJB and other Java EE Technologies and the fly likes usefulness of session beans  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "usefulness of session beans  " Watch "usefulness of session beans  " New topic
Author

usefulness of session beans

satish bodas
Ranch Hand

Joined: Jun 19, 2008
Posts: 116
Am trying to understand where there is a need to use Sessionbeans
( atleast in case of web applications )
My understanding is for web applications - I will save user state in HttpSession .

Now if I use HttpSession I wouldnt want to use Stateful session beans

I would use stateless session beans

Can someone explain a scenario in web applications where it would be useful .

Thanks ,
~satish
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Stateful session beans are useful if your application has state, but you have non-web clients. For example, if you have permissions set when you log in to an app and cahced with your principal and you need those permissions to be the same if you log in again through another app. Make sense?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
satish bodas
Ranch Hand

Joined: Jun 19, 2008
Posts: 116
Thanks Paul for your reply .

What I am a little sore at is - the books about ejb dont mention this point clearly and explicitly .

In the applications that I work in are almost always web applications so i think it would be safe to say bye bye to steful session beans !

Thanks ,
~satish
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    5

Stateful beans are harder to maintain (from a coding stand point) which is why stateless session beans are implemented in practice more often. Often if state is needed its unloaded to a system management component; for example, storing data about a user's current session into a database. The advantage is that the data can be used for customer analysis and disconnected sessions, such as saving a user's shopping cart for future sessions.
[ August 05, 2008: Message edited by: Scott Selikoff ]

My Blog: Down Home Country Coding with Scott Selikoff
Jerwin Louise Uy
Ranch Hand

Joined: Oct 27, 2007
Posts: 75
Stateful session beans maintains conversational state. They are also pooled by the application server in which the session beans are deployed however it requires a lot of resource due to the fact that it has to be serialized when it is not needed and deserialized when it is being demanded by a particular request that is why most web applications use stateless session beans and maintain the conversational state in the session of the web container.


Uy Jerwin Louise Vergara
Junior Developer / Research and Development at Incuventure Partners Corporation
email: jerwin.uy@incuventure.net
Sathish Nagappan
Ranch Hand

Joined: Nov 05, 2005
Posts: 76
Originally posted by Jerwin Louise Uy:
Stateful session beans maintains conversational state. They are also pooled by the application server in which the session beans are deployed


As per my understanding, Stateful session beans are not pooled. They are created by the application server the first time the client creates a session with the EJB container. When the client is inactive, or between invocation of business methods, the Container has the freedom to serialize (passivate in EE terms) and activate (deserialize) Stateful session beans.

Stateless session beans however, are pooled and the same session bean object may service 2 different clients at different points in time without construction and destruction of the actual bean object. With stateful beans, each session from the client would work on a fresh Stateful session bean object.
[ August 06, 2008: Message edited by: Ashwanth Fernando ]

SCJP, SCWCD, SCBCD, IBM XML, IBM OOAD, SCEA 5, ITAC - Distinguished IT Architect.
Jerwin Louise Uy
Ranch Hand

Joined: Oct 27, 2007
Posts: 75
Sorry for the misunderstanding.

Well, technically the ejb container is achieving the "effect of pooling" through passivation and activation so that the same session bean will serve the same instance because it has to conserve resources.

Regards.
Sathish Nagappan
Ranch Hand

Joined: Nov 05, 2005
Posts: 76
Jerwin Louise Uy wrote:Sorry for the misunderstanding.

Well, technically the ejb container is achieving the "effect of pooling" through passivation and activation so that the same session bean will serve the same instance because it has to conserve resources.

Regards.


You misunderstand. There is no "effect of pooling". Pooling only comes into play when the same bean serves multiple clients without being deconstructed and reconstructed again.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: usefulness of session beans
 
Similar Threads
Shopping cart strategy for part 2. JSF with session scope or Stateful Session Beans?
What are the advantages stateful session beans takes over than HttpSession
User Session - Servlet or SFSB
HttpSession Vs Stateful session beans
Best Answer