aspose file tools*
The moose likes Object Relational Mapping and the fly likes Difference between Hibernate and JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Difference between Hibernate and JPA" Watch "Difference between Hibernate and JPA" New topic
Author

Difference between Hibernate and JPA

Tejas Jain
Ranch Hand

Joined: Mar 04, 2008
Posts: 119
How much is the difference between Hibernate and JPA at API level? Can I easily covert an application that use Hibernate to JPA? or vise verse?
Is it wise to select JPA over Hibernate for a fresh new application? I want to go with the standard JPA.

What about iBatis?

Thanks


"Knowing is not enough, you must apply... Willing is not enough, you must do."
--Bruce Lee
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

"The Jain",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names get deleted.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Hibernate implements JPA. So if you use all the class packages of jpa, you can use Hibernate as the implementation of it.

JPA is a spec and not an implementation, so if you choose JPA, you still have to pick an implementation. You can pick Hibernate, Toplink, and any other ORM that implements JPA.

I hope that helps clear things up.

If you find you have an import that is org.hibernate.xxx, then you know you are using something that is Hibernate specific that is not in the JPA spec.

Mark
Tejas Jain
Ranch Hand

Joined: Mar 04, 2008
Posts: 119
Originally posted by Mark Spritzler:

Hibernate implements JPA. So if you use all the class packages of jpa, you can use Hibernate as the implementation of it.

...

If you find you have an import that is org.hibernate.xxx, then you know you are using something that is Hibernate specific that is not in the JPA spec.

Mark


I did not see Hibernate has a package called "javax.persistence" in the Hibernate download. Hibernate provides another product called EJB3 JPA implementation. I would like to know the difference between JPA and original Hibernate specific implementations. Thanks
[ March 14, 2008: Message edited by: Todd Jain ]
Tejas Jain
Ranch Hand

Joined: Mar 04, 2008
Posts: 119
Mark, You still did not answer my question.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Originally posted by Todd Jain:


I did not see Hibernate has a package called "javax.persistence" in the Hibernate download. Hibernate provides another product called EJB3 JPA implementation. I would like to know the difference between JPA and original Hibernate specific implementations. Thanks

[ March 14, 2008: Message edited by: Todd Jain ]


Hibernate implements JPA, you need all the correct Jars. Hibernate has implementations of javax.persistence classes.

Mark
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Sorry, also, I was up at Mammoth Mountain Snowboarding this past weekend.

Mark
Gauravv Gupta
Greenhorn

Joined: Dec 13, 2009
Posts: 2
Hi Friends, Even I have similar doubt about Hibernate 3.
My assumption is hibernate has two types of implementations (1) as a implmenetation of JPA (2) The extension to older hibernate (Without JPA). If we use first case we would have to use query language/syntex provided by JPA whie in second case we would have to use HSQL. and once we write HSQL queries we can't switch to JPA implementation.
Guys, please let me know is it correct ?
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 133
JPA is the subclass of Hibernate. It retains properties of hibernate. Hibernate is the Persistence provider and JPA is the API to implement it. Lets take a example of JDBC API in java and mysql. We use DriverManager.getConnection to get the connection which is defined in Java API but still we need to use mysql jar to connect to the database.

JPA and hibernate works on same principle. JPA is specification and Hibernate is implementation. As per my understanding JPA is better approach to use compare to Hibernate in future migration.
Gauravv Gupta
Greenhorn

Joined: Dec 13, 2009
Posts: 2
Hi Sunil, I agree with your reply. But could you share when HQL comes in the picture since JPA has its own query language? Or is it like while implementing hibernate its upto the programmer with QL to use ?
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 133
Thanks Gaurav, i will try to get back your answer.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

"Gaurav Gg", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42280
    
  64
I think it's likely that Hibernate transforms JPA's QL into HQL before executing it. Seems less work than having two separate QL -> SQL transformation engines.


Ping & DNS - my free Android networking tools app
Rahul Babbar
Ranch Hand

Joined: Jun 28, 2008
Posts: 210
As Mark had mentioned before, JPA is just a specification while Hibernate is one of the implementations..
For an application server to be J2EE compliant, it should support JPA...so what that means is that all the application Servers like Weblogic, Websphere, Jboss etc should implement JPA...
Now, how these servers implement JPA depends on them..eg Jboss implements JPA using Hibernate...while some other server may use some other ORM framework like Toplink..
So...if you are just using JPA on a Jboss server...and some exception comes, related to the persistence layer...you can easily see the stacktrace having hibernate in it...although we did not use Hibernate(because Jboss internally uses hibernate for JPA impl )..

and EJBQL is converted to HQL(or the query language of other ORM framework).


Rahul Babbar
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Difference between Hibernate and JPA