I found a lot of similar questions
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?
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.
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.
JPA can be used without a JPA provider aka Hibernate, EclipseLink and so on only if the application server has already a JPA implementation.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With