EntityManager em = // get entity manager Session session = em.unwrap(Session.class); CriteriaQueryquery = session.createCriteria(Customer.class); // ... define query ... List customers = query.getResultList();
EntityManager em = // get entity manager Session session = em.unwrap(Session.class); Transaction tx = session.beginTransaction(); // ... perform operations ... tx.commit();Here we use the unwrap method to access Hibernate's Transaction API, which allows us to manually manage transactions outside of the JPA API. The javax.persistence.EntityManager interface is part of the JPA specification, which is included in the Java Persistence API (javax.persistence) library. Additional library dependencies may be needed depending on the specific database provider being used.