Ph: 1590594703

EJB fundamentals and session beans

Begin exploring the world of EJBs

Java Enterprise Edition (Java EE) has a powerful facility dedicated to expressing the business logic of an application and for accessing a database using a JavaBeans-like concept. That facility is Enterprise JavaBeans, known as EJBs for short.

In this article, we'll begin exploring the world of EJBs, which is a very important capability of the Java EE platform. EJBs provide infrastructure for developing and deploying mission-critical, enterprise applications. We'll first look at some EJB fundamentals, and then focus on one type of EJB: the session bean.

In this article, you will learn the following:

The benefits of using EJBs The three kinds of EJBs: session, entity, and message-driven beans The makeup of session beans How to develop session beans Differences between stateful and stateless session beans

Understanding EJBs

Application architectures often consist of several tiers that each has its own responsibilities. One such architecture that consists of three tiers is illustrated in the Unified Modeling Language (UML) diagram shown in Figure 1.

[image]

Figure 1. The classic model of a multitiered, or layered, architecture


The two elements on the left side of the diagram in Figure 1 are called components in the UML notation. Components represent software modules. The diagram describes what is called a multitiered, or layered, architecture. Multitiered architectures have many advantages, not the least of which is the ability to change any one of the layers without affecting all of the other layers. This is in contrast to a single-tier architecture, within which all aspects of the program design coexist in a single element. Changes or actions that affect one portion of the single-tier element also potentially affect the other members of that element.

Consider the three-layer architecture shown in Figure 1, consisting of user interface, application logic, and database layers. If the database layer is changed, only the application logic layer is affected. The application logic layer shields the user interface layer from changes to the database layer. This facilitates ongoing maintenance of the application and also increases the application's ability to incorporate new technologies in its layers.

These layers provide an excellent model of how EJBs fit into your overall program design. EJBs provide an application logic layer and a JavaBeans-like abstraction of the database layer. The application logic layer is also known as the middle tier.

Note
JavaBeans and Enterprise JavaBeans are two different things, but because of their similarities (and for marketing reasons), they share a common name. JavaBeans are components built in Java that can be used on any tier in an application. They are often thought of in relationship to servlets and as GUI components. Enterprise JavaBeans are special, server-based components, used for building the business logic and data access functionality of an application.


Why use EJBs?

Not too long ago, when system developers wanted to create an enterprise application, they would often start by "rolling their own" (or purchasing a proprietary) application server to support the functionality of the application logic layer. Some of the features of an application server include the following:

Discuss

Start a new discussion or jump into one of the threads below:

Resources
"EJB Fundamentals and Session Beans" is an excerpt from Beginning Java EE 5From Novice to Professional
http://www.apress.com/book/bookDisplay.html?bID=420 (Apress, October 2005; ISBN1590594703)
Glassfish
https://glassfish.dev.java.net/
For more information about the EJB specification
http://java.sun.com/products/ejb/docs.html
JSR 175A Metadata Facility for the Java Programming Language
http://jcp.org/en/jsr/detail?id=175
For more on EJB 3.0, please read "Simplify Enterprise Java Development with EJB 3.0," Michael Juntao Yuan (JavaWorld):
Part 1Use annotations to develop POJO services (August 2005)
http://www.javaworld.com/javaworld/jw-08-2005/jw-0815-ejb3.html Part 2POJO persistence made easy (September 2005)
http://www.javaworld.com/javaworld/jw-09-2005/jw-0912-ejb.html
For an introduction to annotations, read "Taming Tiger, Part 3Decorate your code with Java annotations," Tarak Modi (JavaWorld, July 2004)
http://www.javaworld.com/javaworld/jw-07-2004/jw-0719-tiger3.html
For more articles on EJB, browse the Enterprise JavaBeans section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-ejbs-index.shtml?
Browse the Java Enterprise Edition section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-j2ee-index.shtml?



You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser