Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between Hibernate Session and EntityManager [duplicate]

What is the difference between the Hibernate Session class and the EntityManager class? I know that EntityManager implements the Java Persistence API, but I am not sure what its relation is with Session. Are they related at all?

like image 940
JRR Avatar asked May 21 '13 12:05

JRR


People also ask

What is the difference between session and EntityManager?

Session is a hibernate-specific API, EntityManager is a standardized API for JPA. You can think of the EntityManager as an adapter class that wraps Session (you can even get the Session object from an EntityManager object via the getDelegate() function).

Does Hibernate use EntityManager?

Hibernate provides implementation of JPA interfaces EntityManagerFactory and EntityManager . EntityManagerFactory provides instances of EntityManager for connecting to same database. All the instances are configured to use the same setting as defined by the default implementation.

What is the difference between session Save () and session persist () method?

1)The first difference between save and persist is there return type. Similar to save method, persist also INSERT records into the database, but return type of persist is void while return type of save is Serializable Object.

What is difference between session and session factory?

SessionFactory is a factory class for Session objects. It is available for the whole application while a Session is only available for particular transaction. Session is short-lived while SessionFactory objects are long-lived. SessionFactory provides a second level cache and Session provides a first level cache.


1 Answers

Session is a hibernate-specific API, EntityManager is a standardized API for JPA. You can think of the EntityManager as an adapter class that wraps Session (you can even get the Session object from an EntityManager object via the getDelegate() function).

This is not dissimilar to other Java APIs around (for example, JDBC is a standard API, each vendor adapts its product to the API via a driver that implements the standard functions).

like image 200
EmirCalabuch Avatar answered Sep 30 '22 12:09

EmirCalabuch