top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

What is the difference between Hibernate and EJB 3?

0 votes
62 views
What is the difference between Hibernate and EJB 3?
posted Mar 28, 2016 by Danial Rotwaski

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

EJB 3.x is a container that's part of the JavaEE stack. It does things like dependency injection and bean lifecycle management. You usually need a full JavaEE application server for EJB3

Hibernate was the first big ORM (Object relational mapper) on the Java Platform, and as such has greatly inspired JPA (which is part of the EJB3 standard but can be used without an EJB container). I would suggest coding against JPA and only using hibernate as a provider, that way you can easily switch to EclipseLink etc.

Hibernate and EJB 3.0

EJB-3 , is the latest version and it is heavily influenced by Hibernate. Some readers equate EJB-3 with Hibernate. Some even equate EJB-3 with JBOSS! Oracle supports EJB-3 proposals and as it is the main Database company in j2ee world, EJB-3 has bright future. J2EE( Java Enterprise Edition) by its very name is an Enterprise level technology, and as EJB is the essence of such Enterprise applications, because of the built-in container services offered, the significance of the surging interest in Hibernate can be really appreciated only in association with EJB and hence a detour into EJB is inevitable.

EJB has three types. One type is the SESSION BEAN,residing in ENTERPRISE container, which can be thought of as a function-bean, invoked in RMI-IIOP style. (this is a rough definition).Such session-bean , may be either stateless or stateful.

This type of EJB has stood the test of time during the last six years and has even gained wide approval, even for data-access, especially since it fits very well with the emerging XML WebService technology, and is very easy to learn and implement.( The earlier tutorial on EJB as webservice in Feb-2005, in DeveloperIQ illustrates this feature).The stateless bean working in Enterprise container has an exact counter-part in Microsoft COM+(MTS), but the other types are said to be available in MS platform only through third-party extensions.

ORM tools have been sometimes used along with Session beans. The only problem till recently was that they were proprietary and rather costly. But nowadays, very reliable open-source ORM tools are available, and even Richard Monson Haefel ( an acknowledged authority and author on EJB)approves this method as a safe and productive alternative to Entity beans.( page-467..EJB by Haefel-OReilly).

The other branch, the ENTITY BEAN has been less lucky. EJB-1.1, EJB-2.0 and then EJB-2.1 , have meant a number of changes in the specification relating to Entity Beans. We can say that an Entity bean is an ‘Attribute bean’ or ‘property-bean’, with setter and getter methods, invoked in RMI-IIOP style and persisted in Enterprise container. The pattern of defining a typical Javabean is a recurring theme in Java. The same style occurs in BDK,EJB-Entity beans, Struts,JSF and now in Hibernate too. So, it is very important and elegant.

The third branch is Messaging paradigm and MDB. A recent article in the web dubbed the ‘RPC’ style, on which the previous two types of EJB are based, as stone-age technologies! An Enterprise by its very name implies huge number of customers and concurrent transactions, RPC style being like telephone call, could result in ‘line-engaged!’ problem. If the call involves the called person referring to some records before replying, it leads to line- blocking. But, messaging style, as in email, at least ensures that the message has been sent. It is evident that dubbing RPC( read ‘telephone’) as unsuitable , is over-statement. Sometimes, we desire immediate response, too. By the same token, even XML webservice , if it is really serious, should adopt messaging style and it does.MDB (Message-Driven bean) has weathered the storm and is in fact gaining more and more acceptance.

answer Mar 28, 2016 by Karthick.c
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...