*
The moose likes Object Relational Mapping and the fly likes Why is JPA used with in Combination with ORM like Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Why is JPA used with in Combination with ORM like Hibernate" Watch "Why is JPA used with in Combination with ORM like Hibernate" New topic
Author

Why is JPA used with in Combination with ORM like Hibernate

RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Hi all ,

I have spent lot of time searching but all in vain

Can anybody please tell me why is JPA used in combination with Hibernate ??

What i mean to ask is that :

Servelts for controlling --->SessionBean 3.0 for flow --->Hibernate for persisting is enough for CRUD operations know ??

why is JPA used in combination with Hibernate ??

Please help me .


If you want something you never had do something which you had never done
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi RaviNada,

as the name - Java Persistence API - suggests JPA is just the API and specification. The idea behind this is that you can use different implementations as long as they are compliant to the spec. Hibernate is one possible persistence provider for the JPA (although Hibernate can be used without JPA). This way if you create code which only relies on the parts of the JPA without using specific features from a persistence provider it's very easy to switch between different implementations. Another popular alternative for example is TopLink.

I hope this makes it clearer ;-)

Marco
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Hi Marco , Thanks for your time .

You mean to say is that JPA is only an API and not programming in which we can embed any ORM layer like Hibernate ,TopLink----etc for performing CRUD operations??(Please correct me if i am wrong here)


so what i understand is that EJB2.1 is a failure and Sun has provided the JPA specs , upon which Hibernate is built on ??

Waiting for answers from you experts on this.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi!

@Sandeep: Of course there are Alternatives to JPA ;-)

@RaviNada: I think you got me wrong. JPA of course uses the said ORM tools under the hood and of course it provides the known CRUD operations to you. Just have a look at the API documentation for the class EntityManager!

There are different reasons why the persistence part was moved to a separate specification and is no longer an integral part of the EJB specification. One reason is that you can use JPA now in standalone applications without EJBs or an EJB container at all. But the main thing here is that the JPA provides a standardized interface to different persistence providers so that you are not forced to use a specific vendor and switch easily between them.


Marco
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528


i am getting little bit by the help provided by you.

I saw these EntityManagerFactory , EntityManager from JPA similiar to SessionFactory and Session onto Hibernate. But still i could not understand.

My Query is that if i use a Weblogic container then no need to use the JPA , as Hibernate is enough to do my work ??
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

I understand your problem. So I'll try to explain it better :-)

The JPA and Hibernate give you almost the same functionality and both are very similar in their usage. The JPA was created to combine and standardize the best ideas of famous ORM tools. For this it's obvious why JPA isn't very much different from Hibernate. As far as I know the Hibernate team (and others) were quite involved in creating the specification and API.

So the question isn't which can do your work better because they can almost do the same things. After all you could use Hibernate as an implementation provider for JPA. As I said the JPA is only the API and specification! It uses Hibernate or another ORM to do all the work! And because JPA is an official standard all compliant containers should support it out of the box without tying you to a specific vendor.

Because the usage of JPA is very easy and similar to Hibernate it's probably better to use JPA in favor of Hibernate because you're free to switch to another implementation later without having to learn everything from scratch. I'm not an expert in persistence questions and I must confess that I only used Hibernate as persistence provider for the JPA but the only reason I see today for using Hibernate without JPA is because you may need a feature which only "plain" Hibernate can provide and which is not part of the JPA. Spontaneously I don't have any idea which features these could be but I'm sure there are enough Hibernate experts here at the JavaRanch who can exactly tell you which features are only available when using Hibernate directly - without JPA.

And to your last question: Hibernate IS enough but in my opinion with JPA you gain the said advantages without having to do more work or learning a lot of new things!


Marco
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Thank you very much Marco Ehrentreich.

Have a Nice day.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is JPA used with in Combination with ORM like Hibernate
 
Similar Threads
JPA Batch Insert
Which JPA RI to use ?
Hibernate and JPA with Spring
Pro JPA 2 - JPA for Hibernate users?
Hibernate suppourt with JPA