5.Enterprise Java Bean

Enterprise Java Bean (EJB) is a managed, server-sided component for modular construction of enterprise applications.

Simple EJB Architecture:

The EJB specification is one of the several Java APIs in the Java Platform, Enterprise Edition. EJB is a server-side component that encapsulates the business logic of an application. The EJB specification was originally developed in 1997 by IBM and later adopted by Sun Microsystems (EJB 1.0 and 1.1) and enhanced under the Java Community Process as JSR 19 (EJB 2.0), JSR 153 (EJB 2.1) and JSR 220 (EJB 3.0).

Rationale: The EJB specification intends to provide a standard way to implement the back-end 'business' code typically found in enterprise applications (as opposed to 'front-end' user-interface code). Such code was frequently found to reproduce the same types of problems, and it was found that solutions to these problems are often re-implemented again and again by programmers. Enterprise Java Beans were intended to handle these common concerns such as persistence, transactional integrity, and security in a standard way, leaving programmers free to concentrate on the particular program at hand.

Accordingly, the EJB specification details how an application server provides:

  • Persistence
  • Transaction processing
  • Concurrency control
  • Events using Java Message Service
  • naming and directory services (JNDI)
  • Security ( JCE and JAAS )
  • Deployment of software components in an application server
  • Remote procedure calls using RMI-IIOP.
  • Exposing business methods as Web Services.

Additionally, the Enterprise JavaBean specification defines the roles played by the EJB container and the EJBs as well as how to deploy the EJBs in a container.


Rapid adoption followed by criticism: This vision was persuasively presented by EJB advocates such as IBM and Sun Microsystems, and Enterprise JavaBeans were quickly adopted by large companies. Problems were quick to appear, however, and the reputation of EJBs began to suffer as a result. For starters, the APIs of the standard were far more complex than what typical developers are used to. An abundance of checked exceptions, required interfaces, and the implementation of the bean class as an abstract class were all unusual and counter-intuitive for many programmers. Granted, the problems that the EJB standard was attempting to address, such as object-relational mapping andtransactional integrity, are complex. However many programmers found the APIs to be just as difficult if not more so, leading to a widespread perception that EJBs introduced complexity without delivering real benefits.

In addition, businesses found that using EJBs to encapsulate business logic brought a performance penalty. This is because the original specification only allowed for remote method invocation through CORBA (and optionally other protocols), even though the large majority of business applications actually do not require this distributed computing functionality. The EJB 2.0 specification addressed this concern by adding the concept of Local interfaces which could be called directly without performance penalties by applications that were not distributed over multiple servers.

The complexity issue, however, continued to hinder EJB's acceptance. Although high-quality developer tools made it easy to create and use EJBs by automating most of the repetitive tasks, these tools did not make it any easier to learn how to use the technology. Moreover, a counter-movement had grown up on the grass-roots level among programmers. The main products of this movement were the so-called 'lightweight' (i.e. in comparison to EJB) technologies of Hibernate(for persistence and object-relational mapping) and Spring Framework (which provided an alternate and far less verbose way to encode business logic). Despite their lacking the backing of big businesses that EJBs had, these technologies grew in popularity and were adopted more and more by businesses who had become disillusioned with EJBs.

Reinventing EJBs

Gradually an industry consensus emerged that the original EJB specification's primary virtue--enabling transactional integrity over distributed applications--was not of use to the majority of enterprise applications. The functionality delivered by Spring and Hibernate was what enterprise applications needed. The EJB 3.0 specification was a radical departure from its predecessors, and illustrates this new understanding. It shows a clear influence from Spring in its use of POJOs, and its support fordependency injection to simplify configuration and integration of heterogeneous systems. Hibernate's influence is even more clear as Gavin King, the creator of Hibernate, participated in the EJB 3.0 process and is an outspoken advocate of the technology. Many features originally in Hibernate were incorporated in theJava Persistence API, the replacement for entity beans in EJB 3.0. The EJB 3.0 specification relies heavily on the use of annotations, a feature added to the Java language with its 5.0 release, to enable a much less verbose coding style.

Accordingly, although all versions of the EJB spec seek to deliver a similar functionality, in practical terms EJB 3.0 is very nearly a completely new API, bearing little resemblance to the previous EJB specifications.