Reputation: 103
As we know there are two Persistent contexts in hibernate
namely org.hibernate.Session and javax.persistent.EntityManager
but some of the methods which are there in Session not there in EntityManager
for example
session.delete(entity); is there in Session
but there is no delete in EntityManager
for that we have to use
entityManager.remove(entity); so which Context to use for persisting entity in database and which is faster between two.
As of my knowing differance is
entity instance passed to the org.hibernate.Session delete method can be either in managed or detached state, while the entity instance passed to remove on javax.persistence.EntityManager must be in managed state.
Upvotes: 2
Views: 307
Reputation: 1480
Very Good Question
Many Persistent API's have delegation to org.hibernate API's
so i think better is to use org.hibernate API's directly
Upvotes: 0
Reputation: 200196
There is no performance difference; Hibernate just exposes its services through the JPA's EntityManager
, in addition to the native Session
. If you don't care for JPA compatibility (I don't see any good reason why you should), use the native Session
to leverage the full feature set of Hibernate.
Upvotes: 2