aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes difference between hibernate and ejb Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "difference between hibernate and ejb" Watch "difference between hibernate and ejb" New topic
Author

difference between hibernate and ejb

jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
by my understanding, i believe that ejb is just api , but hibernate is bunch of concrete classes that implement the ejb api.

so what is the difference between them?


Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
not really, Hibernate is just a persistence framework, where you map beans to DB tables, however EJB is much bigger than hibernate and it mainly consists of:

1) persistence layer which are named entity beans.
2) session beans, which contain the business of your operations.
3) message driven beans which are used for Java Messaging.

in addition EJB forces the container to deal with Transaction management, demarcation, resource look up... etc. so when using EJB you will be just seeing business logic and not code used to open sessions, close sessions, manage transactions, timer services ... etc. code is much cleaner and the programmer focus only on the business, and the container does all the job of transactions, sessions etc.

in addition with EJB 3 a new concept of Dependency Injection has been introduced, which makes coding much more easier. don't forget that EJB 3 is a specification and when you are working on big projects (distributed projects) you would feel how much EJB is great.

finally in EJB 3 a new API has been introduced that allows you to map beans to tables using annotations which is the Java Persistence API, and its also used by hibernate . and a new query language somehow similar to HQL but much more powerfull where it allows you to make insert/update queries too.

for my experience EJB 2 is hell, while EJB 3 is really heaven. the only missing thing is the ability of using DI in POJO's too.


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
thank you for your valuable reply
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
why do people always combine hibernate and ejb3 to code their application, instead of just using ejb3? since to me, i feel like ebj3 can do everything hibernate does, and it does something extra, such MDB.
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Jim,

Hibernate 3 implements JPA 1.0, which is part of EJB 3.0 (in fact, becoming EJB 3.0 compliant was the major feature for Hibernate 3, including annotation support). In terms of Hibernate specific features that have not been standardized in EJB 3.0, really the criteria API is the most significant, which is being standardized in JPA 2.0. I personally have never had a reason to use the Hibernate criteria API, so do not consider it that important.

As to POJO injection with EJB 3.0, you can use Seam, Guice or even Spring with EJB 3.0 for that.

Hope it helps,
Reza


Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between hibernate and ejb