I'm using Jersey as WebService and Hibernate EntityManager to persist my data...
The persistence will work correctly if I write my method as this :
@GET @Path("/") public Response test() { EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1"); EntityManager em = emf.createEntityManager(); Test product = new Test("desc"); em.getTransaction().begin(); if (!em.contains(product)) { em.persist(product); em.flush(); } em.getTransaction().commit(); em.close(); emf.close(); return Response.status(Response.Status.OK).build(); } However I want to use the @Transactional from com.google.inject.persist.Transactional to make the code more light :
@GET @Transactional @Path("/") public Response test() { EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1"); EntityManager em = emf.createEntityManager(); Test product = new Test("desc"); em.persist(product); em.close(); emf.close(); return Response.status(Response.Status.OK).build(); } However with this code the data are not recorded into the database !
Any Idea