How to access Hibernate Session in JPA applications?

In order to access Hibernate objects from a JPA application you can use the unwrap method available in the EntityManager and EntityManager Factory class: EntityManager.<T>unwrap(Class<T>) EntityManagerFactory.<T>unwrap(Class<T>) This method can be used to gain access of JPA-vendor-specific classes. For example, here is how you can retrieve Hibernate’s Session and SessionFactory: Session session = em.unwrap(Session.class); SessionFactory sessionFactory … Read more

How do you retrieve Hibernate’s Session from an Entity ?

This tutorial has been written for JBoss 5 and it is therefore obsolete. Check this article to learn how to use Hibernate objects from your Entity EJB: How to access Hibernate Session in JPA applications? Reading the EJB 3.0 documentation it should be simply obtained by casting the EntityManager instance. org.hibernate.Session session = (org.hibernate.Session)entityManager; However, … Read more