Modelling using Session and Entity EJBs

Gopalan Suresh Raj


Use Session Beans for Application logic
Use Session Beans as the only interface to the client
Expect little reuse of session beans
Use session beans to control the workflow of a group of entity beans
Use Entity Beans to develop a persistent object model (wrap all yr. JDBC code)
Use Entity Beans to enforce accuracy/integrity of your database
Insist on reuse of Entity Beans
Use Entity Beans to model domain objects with a unique identity shared by multiple clients

In general Session Beans are about a conversation with a client, and Entity Beans are about records in the domain model.

Use entity beans for a persistant object model: e.g., wrap up all your jdbc code etc. giving the rest of your application an object-oriented interface to your data model. Session beans are for application logic. For example, use session beans to model the layer that interfaces with your object-model but normally should not go direct to your database. Thus a set of session beans provide all the functionality for a particular application of which there could be several communicating with the Entity based Object-Model. It will be session bean's EJBobjects that communicate with the front-end GUI code (or servlets etc.). However, also be aware that entity beans can have an object model behavior too. As always, there are no hard and fast rules.
Use Session Beans as the only interface to the client, providing a "coarse grained" facade to the underlying model. You should use entity beans to enforce the accuracy/ integrity/ auditability of databases, not merely as an OO representation of data. Then use session beans to run the processes that operate on the databases. This split reduces the pain of introducing new/ changed processes because testing/ approval does not need to be so stringent.
Insist on reuse of entity beans. They'll be hard to develop but over time they'll "define your company".
Expect little reuse of session beans. Plan instead to discard them and create new ones quickly by building a RAD capability around them as a means to competitiveness.
Elevate Entities to a much higher level. Entities are good candidates to model business objects/ domain objects which have a unique identity and need to be shared by various clients and be persisted over a longer time. They can also incorporate the business logic that goes on with their responsibility. Session Beans can be used whenever a business method requires services from two or more entities. It is a good idea to have all interfaces to the system through Sessions beans.

click here to go to
My EJB HomePage...


About the Author...
Gopalan Suresh Raj is a Software Architect, Developer and an active Author. He is contributing author to a couple of books "Enterprise Java Computing-Applications and Architecture" and "The Awesome Power of JavaBeans". His expertise spans enterprise component architectures and distributed object computing. Visit him at his Web Cornucopia site ( or mail him at

Go to the Component Engineering Cornucopia page

This site was developed and is maintained by Gopalan Suresh Raj

This page has been visited times since July 19,1998.

Last Updated : Dec 19, '98

If you have any questions, comments, or problems regarding this site, please write to me I would love to hear from you.

Copyright (c) 1997-98, Gopalan Suresh Raj - All rights reserved. Terms of use.

All products and companies mentioned at this site are trademarks of their respective owners.