@Test public void testSession() { Thing t=null; try(Session session = JPASessionUtil.getSession("utiljpa")) { Transaction tx = session.beginTransaction(); t = new Thing(); t.setName("Thing 2"); session.persist(t); tx.commit(); } try(Session session = JPASessionUtil.getSession("utiljpa")) { Transaction tx = session.beginTransaction(); Query<Thing> q = session.createQuery("from Thing t where t.name=:name", Thing.class); q.setParameter("name", "Thing 2"); Thing result = q.uniqueResult(); assertNotNull(result); assertEquals(result, t); session.delete(result); tx.commit(); } }
public static Session getSession(String persistenceUnitName) { return getEntityManager(persistenceUnitName).unwrap(Session.class); }
JPASessionUtil { public static Session getSession(String persistenceUnitName) { return getEntityManager(persistenceUnitName).unwrap(Session.class); } }
JPASessionUtil { public static Session getSession(String persistenceUnitName) { return getEntityManager(persistenceUnitName).unwrap(Session.class); }  }
JPASessionUtil { public static Session getSession(String persistenceUnitName) { return getEntityManager(persistenceUnitName).unwrap(Session.class); }  @SuppressWarnings("WeakerAccess") static synchronized EntityManager getEntityManager(String persistenceUnitName); static Session getSession(String persistenceUnitName); }
JPASessionUtil { public static Session getSession(String persistenceUnitName) { return getEntityManager(persistenceUnitName).unwrap(Session.class); }  @SuppressWarnings("WeakerAccess") static synchronized EntityManager getEntityManager(String persistenceUnitName); static Session getSession(String persistenceUnitName);  }