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.
Share
Because the
EntityManageris 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
EntityManagerhas a delegate, based on the concrete implementation. For Hibernate the delegate is theSession. If you callgetDelegate()it will return the currentSession.I’ve always used hibernate with JPA (EntityManager) and had very rarely had the need to obtain the Session.