Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we use both EJB and Hibernate in the same project

 
Papa Rao Ushala
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we can use both EJB and Hibernate in the same project? What would be the role of EJB and Hibernate.
How the transactions will be handled , and how the business flow will be?

If the transactions are handled by EJB, then what is the HIbernate role?
If the transactions are handled by Hibernate, then what is the EJB role?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34196
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

Yes. First, keep in mind that EJBs can be session beans, entity beans (in EJB 2) or message driven beans. Only entity beans serve the same purpose as hibernate. Using the other two types of EJB doesn't introduce two technologies with the same purpose.

In EJB 3, entity beans became an API called JPA. Hibernate is also an implementation of JPA. As you can see, these technologies are designed to work well together.
 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm wondering which version of EJB you are referring to. You will be surprised how Hibernate plays a very important role in the EJB 3 world.

Prior to EJB 3, there exist Entity Beans which I don't think integrates nicely with Hibernate.

But then EJB 3 came, along with the new JPA specification (Java Persistence API), whose concepts were mostly derived from Hibernate (courtesy of Gavin King).

In fact, Hibernate is an implementation of JPA (TopLink is another famous implementation). So if you use JPA, I don't think transactions can be handled solely by either EJB or by Hibernate since they are now on the SAME team.

I think the more specific question would now be whether you want JTA transactions or resource local transactions.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prior to EJB 3, there exist Entity Beans which I don't think integrates nicely with Hibernate.

Of course, you probably wouldn't use Entity Beans anyway because of their many well documented failings. Using Hiberate and session beans is a fine mix.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic