views:

974

answers:

1

What are the advantages and disadvantages of Hibernate & EJB3 relative to each other?

I found this post, but it didn't really address my question. If I don't have any particular tie to either technology, what would cause me to pick one over the other? Or are there situations where I would want to use both?

Thanks, Zack

edit: in response to comments: I don't know much about EJB3. I'm just trying to learn if it's something that would be viable for my company. If EJB3 isn't comparable to Hibernate, please explain why.

+4  A: 

JPA provides a subset of Hibernate functionality, but EJB3 provides other services that Hibernate does not address (e.g. Web services, EJBs, Timer service)

JPA offers the following benefits compared to Hibernate:

  • Standardized API
  • Vendor independence (can switch between Hibernate, TopLink, OpenEJB, etc.)

Hibernate offers the following benefits:

  • Widely used
  • De facto standard
  • Direct support from Spring, Grails, etc.
  • Possibly better tools support
  • More features than JPA

What you can do is write your application in EJB using JPA and then when necessary use Hibernate-specific features. Or just use plain Hibernate for persistence if you don't care about standardization and vendor lock-in. Realistically, it's unlikely you will switch between Hibernate and another provider, but it does happen.

Ken Liu
Nitpick: Spring also supports JPA
Pascal Thivent
yeah, but he didn't ask about Spring...
Ken Liu