40

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?

JRR
  • 6,014
  • 6
  • 39
  • 59

1 Answers1

40

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).

EmirCalabuch
  • 4,756
  • 1
  • 25
  • 20
  • is there a difference between them in functionality or they more or less identical? – Alexey Dec 13 '16 at 11:44
  • 1
    They are not identical (functions have different names and even different purposes, annotations are different, etc.). What hibernate (and every other JPA vendor around) does is provide an adapter object that creates the EntityManager functionality by calling the native hibernate API. – EmirCalabuch Apr 28 '17 at 15:03
  • does entity manager creates a new session everytime requested? just curious about it – Yogesh Katkar Feb 04 '20 at 06:52