An Overview of EJB Technology

What Is an Enterprise Bean :

EJB is a server-side component that encapsulates the business logic of an application.


It is a platform for building portable, reusable, and scalable business applications which allows to focus on building business logic without having to spend time on building infrastructure code for services such as transactions, security, automated persistence etc.


An EJB is a piece of Java code that executes in a specialized runtime environment (Application Server).

What Is an Enterprise Bean :

EJB is a server-side component that encapsulates the business logic of an application.


It is a platform for building portable, reusable, and scalable business applications which allows to focus on building business logic without having to spend time on building infrastructure code for services such as transactions, security, automated persistence etc.


An EJB is a piece of Java code that executes in a specialized runtime environment (Application Server).





Benefits of Enterprise Beans :

EJB container provides system-level services to enterprise beans, the bean developer can concentrate on writing business logic.


The beans contain the application business logic, the client developer can focus on the presentation of the client.


Because enterprise beans are portable components, the application assembler can build new applications from existing beans.

When to Use Enterprise Beans :

  • The application must be scalable.
  • Transactions must ensure data integrity.
  • The application will have a variety of clients

EJB 3.0 vs EJB 2.1 :

  • EJB 3.0 is much faster than EJB 2.

  • An EJB 2.1 session bean must implement the SessionBean interface.

  • EJB 3.0 session bean class includes only business methods.

  • EJB 3.0 interfaces are POJI business interfaces and do not require home and component interfaces.

  • EJB 2.1 must have the deployment descriptor, but in EJB 3.0 it is optional. Annotations are added to EJB3.

  • EJB 3 introduced persistence API for database access. In EJB 2 you can use Entity bean.

  • An EJB 2.1 Entity EJB bean class must implement the EntityBean interface and must provide implementation to the ejbCreate() and ejbPostCreate() methods.

  • An EJB 2.1 bean must define resource-ref in ejb-jar.xml to lookup resources. An EJB 3.0 bean can use either dependency injection or JNDI lookup.

  • You couldn’t send an EJB 2 entity bean across the wire in different tiers.They are permanently attached to the database.You have to write data transfer objects.



Benefits Of EJB 3.0 :

  • Easy to use

  • EJB 3 offers a complete stack of server solutions Persistence, messaging, lightweight scheduling, remoting, web services, dependency injection (DI) and interceptors You won't have to spend a lot of time looking for third-party tools

  • EJB 3 will provide Clustering, load balancing, and fail over support with no changes to code, no third-party tool integration, and relatively simple configuration.

  • All EJB 3 components are POJOs, they can easily be executed outside the container .It is possible to unit-test all component business logic using testing frameworks.

EJB Container :

EJB Container is responsible for managing your enterprise bean.The most important responsibility of the container is to provide a secure,transactional,distributed environment in which EJB can execute.

The container transparently provides EJB component services like Transactions, security management ,Remoting and web services support.

A Java EE container is an application server solution that supports EJB 3, a web container, and other Java EE APIs and services.

Types of Enterprise Beans :

EJB 3.0 defines two types of enterprise beans.

  1. Session Bean
  2. Message driven bean

Session Bean :

A session is a connection between a client and a server that lasts for a finite period of time.

Session beans centers on the idea that each request by a client to complete a distinct business process is completed in a session.

There are three types of SessionBean Stateless, Statefull & Singleton.

Stateless Session bean :

A stateless session bean does not maintain a conversational state with the client. When a client invokes the methods of a stateless bean, the bean's instance variables may contain a state specific to that client but only for the duration of the invocation.

A stateless session bean can implement a web service.

Stateful Session Bean :

In a stateful session bean, the instance variables represent the state of a unique client/bean session.

Singleton Session Bean :

A singleton session bean is instantiated once per application and exists for the life cycle of the application.

Message-Driven Bean :

Message driven bean acts as a listener for a particular messaging type, such as the Java Message Service(JMS) API.

Note: We are going to use Eclipse Indigo(IDE),Jboss 5.1 server and MySql Database for sample application so you need to install these software in your system.In Next tutorial, we will discuss how to setup jboss server in eclipse.




comments powered by Disqus