Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Hibernate and Hibernate JPA

I found a lot of similar questions

  • Difference between Hibernate library and Hibernate JPA library
  • What's the difference between JPA and Hibernate?
  • similarity and difference between jpa and hibernate

but no one answers my next question. What diference between classical hibernate approach using org.hibernate.SessionFactory and JPA javax.persistence.EntityManager implementation? I heard, that this JPA implementation uses org.hibernate.SessionFactory and works like wrapper, is it real?

like image 479
Lies Avatar asked Feb 21 '13 12:02

Lies


People also ask

Which is best Hibernate or JPA?

JPA is a standard, while Hibernate is not. In hibernate, we use Session for handling the persistence of data, while in JPA, we use Entity Manager. The query language in Hibernate is Hibernate Query language, while in JPA, the query language is Java Persistence query language. Hibernate is one of the most JPA providers.

What is difference between Hibernate and Spring data JPA?

JPA uses EntityManager interface to create/read/delete operation and maintains the persistence context. Hibernate uses Session interface to create/read/delete operation and maintains the persistence context. JPA uses JPQL (Java Persistence Query Language) as Object Oriented Query language for database operations.

Can I use JPA without Hibernate?

JPA can be used without a JPA provider aka Hibernate, EclipseLink and so on only if the application server has already a JPA implementation.

What is the difference between JPA and Hibernate and JDBC?

Hibernate is an implementation of JPA(Java Persistence API). 1. In JDBC, one needs to write code to map the object model's data representation to the schema of the relational model. Hibernate maps the object model's data to the schema of the database itself with the help of annotations.


3 Answers

Indeed.

JPA is simply an API that allows you to abstract from the used persistence layer. Hibernate provides an implementation of the EntityManager interface that acts as an adapter - it uses the same underlying methods as a hibernate SessionManager.

The idea is that you could, for example, switch your implementation to Eclipse Link and not have to change any of your source code.

like image 146
Boris the Spider Avatar answered Sep 21 '22 17:09

Boris the Spider


JPA is just a specification, meaning there is no implementation. You can annotate your classes as much as you would like with JPA annotations, however without an implementation nothing will happen. Think of JPA as the guidelines that must be followed or an interface, while Hibernate's JPA implementation is code that meets the API as defined by the JPA specification and provides the under the hood functionality.

When you use Hibernate with JPA you are actually using the Hibernate JPA implementation. The benefit of this is that you can swap out Hibernate's implementation of JPA for another implementation of the JPA specification. When you use straight Hibernate you are locking into the implementation because other ORMs may use different methods/configurations and annotations, therefore you cannot just switch over to another ORM.

like image 33
Vipin Singh Avatar answered Sep 20 '22 17:09

Vipin Singh


Here is the answer of you question

What diference between classical hibernate approach using
org.hibernate.SessionFactory and JPA javax.persistence.EntityManager
implementation?

org.hibernate.SessionFactory 

if you change the undeline ORM to IBatis(for e.g) you need to change the code as well.

javax.persistence.EntityManager 

if you change the undeline ORM to IBatis(for e.g) you dont need to change the code.

like image 45
Jaydeep Rajput Avatar answered Sep 22 '22 17:09

Jaydeep Rajput