What is the right way to use entitymanager
问题 I have a REST client in Jersey JAX-RS which takes requests and then using Hibernate's JPA implementation retrieves the data from the database and returns a JSON. Using a shared entity manager, the performance is quite good but if there are multiple requests, I get exceptions from Hibernate, mainly NullPointerException. If I use an entity manager per request I don't get any exceptions but the performance is lower. What is the proper way of handling the EntityManager? EDIT: Following Albert's