The code I was trying to use before was supposed to inject the entityManager inside it. I tried using that but got a nullPointerException cause it apparently hadn't been initialized. I read somewhere that it won't be initialized until after the constructor for the bean is called, so I made a separate function that is called after construction and still no go.
log.debug("initializing session"); EntityManagerFactory emf = Persistence.createEntityManagerFactory("defaultStorage"); EntityManager em = emf.createEntityManager(); // Retrieve an application managed entity manager org.hibernate.Session session = hibernateStorage.getSessionFactory().getCurrentSession(); session.beginTransaction(); Query query = em.createNamedQuery("Session.findBySessionId"); query.setParameter("sessionId", sessionId); Session loadedSession = (Session) query.getSingleResult(); session.getTransaction().commit();
So, my question is:
@PersistenceContext(unitName = "persistenceUnit") private EntityManager em;