Monday, December 9, 2013

Difference Between EJB2 and EJB3

EJB2 vs EJB3 
EJB (Enterprise JavaBeans) is a Java API (Application Programming Interface) found within Java EE (Java Platform, Enterprise Edition) specification. EJB describes an architectural model for the development of enterprise applications. This is a managed server-side model that is able to capture the business logic of the enterprise application. IBM is EJB’s original creator who developed it in 1997. Sun Microsystems adopted it in 1999.
Before the introduction of EJB, it was found that solutions to problems found in back-end business code were frequently re-implemented by the programmers. As a result, EJB was introduced to address these common problems such as persistence, transactional integrity and security. EJB provides standard ways to handle these back end problems, by specifying how the application server should process transactions, integrate with JPA (Java Persistence API) services, handle concurrency control, handle JMS (Java Message Service) Events, resolve naming issues with JNDI (Java Naming and Directory Interface), develop secure programs with JCE (Java Cryptography Extension) and JAAS (Java Authentication and Authorization Service), deploy components, communicate remotely with RMI-IIOP (Java Remote Method Invocation interface over the Internet Inter-Orb Protocol), develop web services, invoke asynchronous methods and use the Timer service.
EJB2
EJB2 (EJB 2.0) was released on 22 August, 2001. It describes specification for developing distributed object-oriented applications in Java by combining tools developed by different vendors. One of the major goals of EJB2 was to allow programmers to develop enterprise applications more easily without having to understand low-level details, such as multi-threading and connection pooling. Another goal was to allow programmers to write a “Bean” once and run anywhere without recompilation (adhering to the “write once, run anywhere” slogan of the Java programming language). Furthermore, EJB2 intended to allow components developed by different vendors to easily interoperate, and allow vendors to write extensions for their products that can support EJBs.
EJB3
EJB3 (EJB 3.0) was released on 11 May, 2006. EJB3 made programmers life very easy by allowing them to use annotations in place of deployment descriptors that were used in previous versions. EJB3 contains a business interface and a specific entity bean that can implement that business interface, removing the need for using home/remote interfaces and the ejb-jar.xml file. Overall performance of EJB3 is much improved compared to EJB2, and there is a considerable increase in configurability, flexibility and portability in this release of EJB.
What is the difference between EJB2 and EJB3?
EJB3 has a noticeable improvement in configuration and performance over EJB2. One reason for this performance improvement is the use of the POJO (Plain Old Java Object) with metadata and XML Deployment Descriptors by EJB3 instead of JNDI lookups used in EJB2 for object references. Configuration of EJB3 is much simpler because the programmer does not need to implement Home/Remote interfaces and others (e.g. SessionBean), which removes the need to use container callback methods (such as ejbActivate and ejbStore).
Furthermore, EJB3 is better than EJB2 in the areas of flexibility and portability. For example, it is easy to convert EJB3 entities to DAO (Data Access Object) and vice versa because EJB3 entities are lightweight (as opposed to the heavyweight EJB2 entities, which implement above mentioned interfaces). Database queries written in EJB3 are very flexible because it uses a refined EJB-QL, in place of the older version of EJB-QL, which had several limitations. EJB3 removes all the portability issues of EJB2 (which uses entity beans for database access) by supporting more generalized JPA for all data transactions.
Unlike EJB2, which needs an EJB container to execute, EJB3 can be executed in an independent JVM (Java Virtual Machine) without having to use containers (this is possible because it does not implement standard interfaces). Unlike EJB2, EJB3 is easily pluggable with persistence providers offered by third parties. Another important difference between EJB3 and EJB2 is that EJB3 can use annotation based security, while EJB2 used deployment descriptors based security. This means that configuration and setup tasks are much easier in EJB3, and there is a considerable reduction in performance overheads compared to EJB2.

No comments: