Home arrow Java arrow Page 2 - Session Beans in EJB 3.0
JAVA

Session Beans in EJB 3.0


Enterprise applications revolve mostly around three aspects of data: transfer of data, retrieval of data and transformation of data by applying the business rules of a particular organization. Since these three aspects are specific to an organization, Enterprise Java Beans (EJB) are known as Business Specific Components. Even among the three aspects, the former two are more generic in nature whereas the latter is closer to the policies of a given organization.

Author Info:
By: A.P.Rajshekhar
Rating: 4 stars4 stars4 stars4 stars4 stars / 7
March 28, 2007
TABLE OF CONTENTS:
  1. · Session Beans in EJB 3.0
  2. · Stateful Session Beans
  3. · Implementing Session Beans
  4. · Session Beans in the Real World

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Session Beans in EJB 3.0 - Stateful Session Beans
(Page 2 of 4 )

According to the definition a Stateful Session Bean is "A bean that is designed to service business processes that span multiple method requests or transactions." Since the Stateful Session Bean is designed for servicing requests spanning multiple method calls, it saves the Conversational State for each client. So for each client a different Bean instance services the request. The main characteristic features of Stateful Beans are:

  1. The state of the bean represents the conversation between the client and the bean.
  2. The bean instance holds information about the client across method calls/invocations.
  3. The Stateful Bean mediates between client and other components of the system to present simplified view to the client.



Though the third property can be attributed to Stateless Session Beans as well, the "stateful" property of the Stateful Session Bean makes it a better candidate to be the mediator. The next important point to be kept in mind is about the instance variables. Whenever an instance variable comes into the picture, the following is true it if it is a part of the Conversational State:

  1. The member variable is transient and its data type is primitive i.e. it's of type int, boolean etc.
  2. It is of non transient Java object type i.e. it's an instance of another class.

If the above points are satisfied then that member variable becomes a part of a Conversational State. In other words the states of such variables are saved and updated according to the method invocations and across method invocations.

The next aspect is pooling. Since the Conversational State has to be saved, the logic behind pooling of Stateful Session Bean is complex. I will be discussing it in the future.

An example of a use of a Stateful Session Bean is a shopping cart. Each time a user adds a product, a method invocation occurs and a request is sent to the bean instance; the bean executes the logic and saves the current result. When the user checks out, the final result (in this case the total cost of the cart) is given. The focus here is on tracking the user requests until checkout is performed which may be after many requests. And tracking a user across requests is the forte of Stateful Session Beans. Next let's look at the steps involved in developing both sub-types of Session Beans.


blog comments powered by Disqus
JAVA ARTICLES

- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...
- Generics and Limitations in Java
- Getting Started with Java Web Development in...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials