This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Object Relational Mapping and the fly likes JPA v/s Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA v/s Hibernate" Watch "JPA v/s Hibernate" New topic
Author

JPA v/s Hibernate

Rudradutt Joshi
Ranch Hand

Joined: Dec 06, 2008
Posts: 45

Hello All,

I was creating a Struts+Spring+hibernate+JPA application, as on the struts web site. I was wondering, what is the reason to use JPA and hibernate, as either of them are also fine as for an ORM. And also which one is better and why???

Regards,
Rudradutt Joshi
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

Rudradutt,

JPA is a specification which lays down a set of standard rules which are followed by implementations of that specification. Hibernate is just one such implementation of that specification. Hibernate in addition to complying with JPA, might provide its own vendor specific features.


[My Blog] [JavaRanch Journal]
Rudradutt Joshi
Ranch Hand

Joined: Dec 06, 2008
Posts: 45

Thank you for your reply,

At a phase, I required to build a query with criteria (hibernate), but as I am using JPA over hibernate, Entitymanager do not provides support for criteria, and indeed its a power full api. Can you please explain me how or why for the same?
Damodar Mukherjee
Ranch Hand

Joined: Mar 20, 2007
Posts: 135
Hi Jaikiran Pai,

Can You please explain how Hibernate fits with EJB3?

Why people use Hibernate in EJB3 projects as EJB3 has a rich Entity Bean?

Thank You in Advance...


SCJP 1.5, SCWCD 1.4, Next... SCBCD5
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

Originally posted by Damodar Mukherjee:
Can You please explain how Hibernate fits with EJB3?

To be very clear Hibernate is not part of the EJB3 spec. Hibernate is an ORM tool and is an implementation of the JPA specification. The JPA spec is part of EJB3.

Originally posted by Damodar Mukherjee:
Why people use Hibernate in EJB3 projects as EJB3 has a rich Entity Bean?



In EJB3, the entity beans are refered to as just Entities (since they are just Plain Old Java Objects). The persistence capabilities for Entities are provided by persistence providers (Ex: Hibernate, TopLink etc...) which follow the JPA spec.
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Jaikiran Pai wrote:Rudradutt,

JPA is a specification which lays down a set of standard rules which are followed by implementations of that specification. Hibernate is just one such implementation of that specification. Hibernate in addition to complying with JPA, might provide its own vendor specific features.



First of all sorry for extending the Thread .

What advantage do we get by getting Hibernate instances / components through JPA specified API .(instead of using Hibernate directly)??

Waiting for your valuable responses


If you want something you never had do something which you had never done
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Same advantage you have getting any implementation through an interface. You can change the implementation without changing your application logic.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rahul Babbar
Ranch Hand

Joined: Jun 28, 2008
Posts: 210
I think JPA was enriched as part of EJB3 and many companies like to follow standards, and EJB is one such standard prevalent throughout the industry.
If a particular organisation is using EJB stateless session beans, it may use JPA over hibernate.
In other words, its all about standards that organisations follow.


Rahul Babbar
 
jQuery in Action, 2nd edition
 
subject: JPA v/s Hibernate