Q1: What is the difference between Hibernate and EJB 2.1? Q2: Which one, among EJB 2.1 and Hibernate, is better?Explain with reason.Q3: When to use EJB 2.1 and when to use Hibernate? Explain with scenarios.

Showing Answers 1 - 9 of 9 Answers

Anuj Kumar Ratra

  • Feb 7th, 2007
 

Ans1: hibernate is a ORM(object relation mapping ) tool which can be used for creating a mapping between plain java bean objects (POJO) and a persitent storage (rdbms).The EJB 3.0 specififcation is divided into two parts the first which deals with session and MDBs and the second which deals with persistence and entity beans. The latter part is called JPA(java persistance API ). HIbernate 3.0 implements the JPA specification.EJB 2.1 is a specification for defining loosely coupled reusable business componenets.ans 2 & 3 ) EJB 2.1 and hibernate serve two different purposes. Hibernate can be co related with the entity beans in EJB 2.1.HIbernate offers far more extensive features then plain entity beans.still there are no containers (applicaiton servers) available which fully implement the EJB 3.0 specification. depending upon the buisness needs hibernate framework can be used in conjuction with EJB2.1 to achieve the JPA abstraction.

sony v george

  • Apr 4th, 2007
 


Basically Ejb and Hibenate is enterly different one But having realtion with Entitybean in Ejb and Hibernate.

Entity bean is also used for object orientd view . It need lot things to configures fo make it possible and Lot of coding need for it. After all the performance is also very few. In ejb egar loading approch has taken for loading it will cause serious performance issues. In java the most concept is polymorphisum and inheritance. We cant get the favour of these concept .

For avoiding it new approch had taken thats called hibernate. Using pojo(plain java object) and .hbm file we can make it possible. There is having all the advantage of Object oriented
view.

Advantages of Hibernate Over EJB
Entity bean is also used for object oriented view. It needs lot of things to configure for make it possible and Lot of coding need for it. After all these performance will be decrease. In ejb’s eager loading approach has taken for loading it will cause serious performance issues. We can’t get the favour of inheritance and Polymorphism.
It helps reduce the lines of code, makes system more understandable and emphasizes more on business logic rather than persistence work (SQL’s). More important, a system with less code is easier to re-factor.
In hibernate productivity, maintainability and portability more than EJB. Hibernate is light weight than EJB and also Hibernate having two-level cache technique but where as EJB not. So that we can have ultra high performance in hibernate.

Hibernate is smaller, lighter, and easier to use compared to the EJB mega-frameworks.
1- Hibernate is more powerful.
You can express many things with Hibernate that cannot be done with CMPs (At least without resorting to Server specific functions, which would make your app less portable). Things like ordering of results, placing limits/offset on the data you require (useful for paging) Dynamic queries etc.
2- Hibernate uses POJOs.
3- Performance
4- Easy to use
Hibernate is more useful than ejb, because it is simple, no need to create a structure There is less database connectivity code Easier to use when your database is varying that is for extensibity It uses cashing so less database transaction
Conclusion: if we want to get all features of hibernate we can go for EJB 3.0, but it’s supported by JDK 1.5 onwards.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions