P. 1


|Views: 217|Likes:
Published by Sudhanshu
Enterprise Java Beans
Enterprise Java Beans

More info:

Categories:Types, School Work
Published by: Sudhanshu on Apr 01, 2010
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PPT, PDF, TXT or read online from Scribd
See more
See less






Prof R P Saw

EJB in J2EE Server

Enterprise JavaBeans Technology 

Definition EJB technology can be defined as a Javabased, server-side, reusable component framework for distributed applications.

EJB Framework  

This framework facilitates centrally managed business logic, declarative deployment, and object persistence. Some of the characteristics of the EJB framework are as follows:
EJBs are Java objects executed within a server environment. EJBs can be distributed across many machines and accessed remotely as if they were on a local machine. EJBs are centrally managed by a container. Central to the EJB specification and architecture is an artifact known as an Enterprise Java Bean (which, like the framework, is often given the acronym EJB).

EJB Framework & JavaBeans Framework  

Even though the names from the EJB framework are very similar to the names from the JavaBeans framework, the specifications and designs of each framework are very different. The JavaBeans specification and component model and the Enterprise JavaBeans and component model have very little in common.

EJB Runtime Environment  


An Enterprise JavaBean is a Java object exposing a number of interfaces and which lives and executes inside of a runtime environment known as an EJB container. An Enterprise JavaBean cannot live outside of an EJB container. An EJB container is a runtime environment for managing enterprise beans. The container hosts and manages an enterprise bean in much the same manner that a Java servlet engine hosts a Java servlet. The EJB container instantiates and controls the enterprise beans and provides them with systemlevel services. A client application wishing to interact with an enterprise bean does not have direct access to an enterprise bean. Rather, the bean is isolated from the client application by the container.

Services Provided by an EJB Container
A developer creating the classes and interfaces from which an enterprise bean object will be created can assume the following system-level services will be available from the EJB container:  Transaction management for the bean  Security for the bean  Persistence of the bean  Remote access to the bean  Lifecycle management of the bean  Database-connection pooling  Instance pooling for the bean Because the EJB container handles the bulk of infrastructure-level services for an enterprise bean, a programmer can concentrate on programming the business logic for the enterprise bean.  

An EJB component is a nonvisual server component with methods that typically provide business logic in distributed applications. A remote client, called an EJB client, can invoke these methods, which typically results in database updates.

EJB Framework Constituents 

EJB server The EJB server contains the EJB container, which provides the services required by the EJB component.
Eaxamples EJB Server are: 

Oracle Application server EJB 3.0 IBM WebLogic BEA Sun EAServer is an EJB server. 

EJB client An EJB client usually provides the user-interface logic on a client machine. The EJB client makes calls to remote EJB components on a server and needs to know how to find the EJB server and how to interact with the EJB components.
An EJB component can act as an EJB client by calling methods in another EJB component. 

An EJB client does not communicate directly with an EJB component. The container provides proxy objects that implement the components home and remote interfaces.
The component¶s remote interface defines the business methods that can be called by the client. The client calls the home interface methods to create and destroy proxies for the remote interface.


EJB container The EJB specification defines a container as the environment in which one or more EJB components execute. The container provides the infrastructure required to run distributed components, allowing client and component developers to focus on programming business logic, and not system-level code. EJB component implementation The Java class that runs in the server implements the bean¶s business logic. The class must implement the remote interface methods and additional methods for lifecycle management.  

EJB component types You can implement three types of EJB components, each for a different purpose:
Stateful session beans Stateless session beans Entity beans

Stateful session beans
A stateful session bean manages complex processes or tasks that require the accumulation of data, such as adding items to a Web catalog¶s shopping cart. Stateful session beans : They manage tasks that require more than one method call to complete, but are relatively short-lived. For example, a session bean might manage the process of making an airline reservation. If you create a session bean on a Web server that tracks a user¶s path through the site, the session bean is destroyed when the user leaves the site or idles beyond a specified time 

Stateless session beans
A stateless session bean manages tasks that do not require the keeping of client session data between method calls. Stateless session beans have the following characteristics: Method invocations do not depend on data stored by previous method invocations. There is no affinity between a component instance and a particular client. Each call to a client¶s proxy can invoke a different instance. From the client¶s perspective, different instances of the same component are identical. Unlike stateful session beans, stateless session beans can be pooled by the server, improving overall application performance.    

Entity beans 

An entity bean models a business concept that is a real-world object. For example, an entity bean might represent a scheduled airplane flight, a seat on the airplane, or a passenger¶s frequent-flyer account. Entity beans have the following characteristics:
Each instance represents a row in a persistent database relation, such as a table, view, or the results of a complex query. The bean has a primary key that corresponds to the database relation¶s key, and is represented by a Java datatype or class.


Enterprise JavaBeans is roughly equivalent to Microsoft's Component Object Model/Distributed Component Object Model architecture Originated by Sun Microsystems

EJB programming model 

The EJB specification mandates a programming model; that is,
conventions or protocols and a set of classes and interfaces which make up the EJB API.  

The EJB programming model provides bean developers and EJB server vendors with a set of contracts that defines a common platform for development. The goal of these contracts is to ensure portability across vendors while supporting a rich set of functionality.

EJB 3.0 Background   

Till EJB 2.0, the development of EJB was little complex. Due to this many developers have been turning away from the complexity of EJBs in favor of simpler alternatives. The new EJB 3.0 specification attempts to answer these criticisms by simplifying EJB development.

Complexities with EJB 2.x 


The current EJB model requires you to create several component interfaces and implement several unnecessary callback methods. The component interfaces require implementation of EJBObject or EJBLocalObject and handling of many unnecessary exceptions. The EJB deployment descriptor is complex and error prone. The container-managed persistence, being based on the EJB model, is overly complex to develop and manage. Several basic features are missing--such as a standard way to define a primary key using a database sequence. The EJBQL syntax is very limited. EJB components are not truly object-oriented, as they have restrictions for using inheritance and polymorphism. Developers cannot test EJB modules outside an EJB container and debugging an EJB inside the container is a nightmare. Looking up and invoking an EJB is a complex task. Detailed knowledge of JNDI is required for even the most basic use of an EJB in your application. 

EJB 3.0 is designed to address the complexities of the current EJB model by:
Removing need for unnecessary interfaces and implementation of callback methods Using metadata annotations instead of deployment descriptors Using regular Java classes as EJBs and regular business interfaces for EJBs

Metadata Annotations 

Annotation is a type of attribute-oriented programming annotations are compiled into the classes by the Java compiler at compile-time. From a developer¶s point of view,
annotations are modifiers - just like public etc 

and can be used in classes, fields, methods, parameters, local variables, constructors, enumerations and packages. 

You can use annotations in your Java code by specifying attributes that can be used for generating code, documenting code, or providing special services such as enhanced business-level security or special business logic during runtime.

EJB 3.0 Using POJOs and POJIs  

JavaBeans and interfaces are often referred to as Plain Old Java Objects (POJOs) and Plain Old Java Interfaces (POJIs), respectively. The EJB class and interface will now resemble POJO and POJI respectively. The unnecessary requirement of the artifacts like home interface is being removed. You do not have to implement one of the EJB interfaces(SessionBean, EntityBean or MessageDrivenBean) in javax.ejb package. Instead, you can either use Stateless, Stateful, MessageDriven or Entity to annotate their bean class. For example,

EJB 3.0 Example 

if you were to define a stateless EJB as HelloWorld, you¶d define the EJB as follows:
import javax.ejb.Stateless; @Stateless public class HelloWorldBean implements HelloWorld { public void sayHello(String name) { System.out.println("Hello "+name +" from your first EJB 3.0 component ..."); }

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->