Ejb1 vs Ejb2 vs Ejb3

EJB1 vs. EJB2 vs. EJB3

Ejb1 had limited functionality just as a lady bug that doesn’t do much work still is appreciated by people due to its beauty.

Ejb2 was very heavy like the Elephant with functionalities. Still to take proper use of the elephant power it had to be tamed, or Ejb2 was later simplified to Ejb3

Ejb3 is very simple having power and is serving the people very well like a cow giving milk to the universe.

 

Overview of EJB

Ejb is a platform for building ,reusable, portable and scalable business applications using java.

Ejb helps developers to concentrate on building business logic code without having to build infrastructure code comprising of functionalities including transactions, security, automated persistence that are provided by the Ejb container.

Ejb as Component

Ejbs are server side components that you can use to build parts of an application like business logic or persistence code. These components in Ejb3 are simple POJO with special power. Component means that the user need not know the inner working of the Component, he only needs to know what he has to give and what the Component will give you i.e. application behavior has to be completely encapsulated from the outside world.

There are 3 types of Ejbs. Session beans taking care of business logic. Entity Bean used for persistence. Message driven beans.

One of the most important use of Ejbs is its reusability. E.g. If there is a site for online books that is using an Ejb code for checking credit card. Then if we create another Website for CDs then we can reuse the same credit card Ejb. The first Ejb can be put as an Ejb component or a web service that is used by both applications.

Application1
uses Credit card Ejb

Application2
Ejb as Framework

The Ejb Container houses the Ejb components we develop. This Ejb Container together with the Ejb Component act as a Framework with predefined functionalities. This relieves the programmer from coding certain areas like transaction, security and persistence that are provide by the Ejb Container itself. Like if a programmer is creating a bean related to processing a credit card he need not create coding for the Transaction and Security that is provided by the Ejb Container Automatically.

We can use metadata annotations in our beans to specify what all services and functionalities we require. These are added dynamically when required during deployment. Metadata annotations is a way to specify the properties in a POJO, and these functionalities get automatically added. So we can say a POJO + Metadata annotation=Ejb3 bean. So we don’t need any outside xml configuration files.

Ejb is a specification which is followed by a large group of user vendors creating application server. So all have to follow the same specification making our applications portable.

Domain Driven Design

DDD is the preferred way as compared to the traditional four tired architecture followed by Ejb 2.

Following DDD the domain objects should contain buisness logic and shouldn’t be just a replica of database record. Incase of Ejb 2 beans were not POJOS and didn’t support OO features like inheritance, polymorphism.

Ejb3 helps follow DDD. Beans created using Ejb3 JPA supports polymorphism, inheritance etc.

Why choose EJB 3 among other technologies

Ease of use, Integrated solution stack— Ejb3 offers a complete stack of server solutions, including persistence, dependency injection, interceptors i.e. we won’t need to look for third party solutions to integrate in our application.

Leave a Reply