I have used this tutorial them same way in my application: http://www.benmccann.com/hibernate-with-jpa-annotations-and-guice/
My app is JAX-RS web service which will
The problem was that my endpoint was annotated with @Singleton so it reused the same EntityManager during concurrent calls. After removing @Singleton, during concurrent calls, different EntityManager objects are used. If endpoint calls are subsequent, it may be that previous/old EntityManager will be used.
Highly simplified example:
@Path("/v1/items")
public class ItemsService {
@Inject
private EntityManager entityManager;
@POST
@Path("/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public void saveItem(){
entityManager.getTransaction().begin();
entityManager.persist(new Item());
entityManager.getTransaction().commit();
}
}