I am using Hibernate to map objects to entities and I have started to use an Entity Manager. This might be a silly question but what actually is the reason for using the entity manager? Previously I would have used a HibernateSessionFactory to get a session and then use that session to pull/push data.
Because the EntityManager
is part of the standard - JPA. Theoretically, you can switch implementations (Hibernate, EclipseLink, OpenJPA) if you need to. Apart from alleged portability there isn't such a big difference between the two.
Hibernate implements the JPA standard. In fact, the EntityManager
has a delegate, based on the concrete implementation. For Hibernate the delegate is the Session
. If you call getDelegate()
it will return the current Session
.
I've always used hibernate with JPA (EntityManager) and had very rarely had the need to obtain the Session.
EntityManager is a concept of JPA. You dont need to use JPA with Hibernate at all (in fact, if it's JPA1, I would suggest you dont).
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