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
Joined: May 20, 2008
thank you for your valuable reply
Joined: May 20, 2008
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.
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,
Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1