title: How frequently should I create an EntityManager?
body: <p>I have an <code>EntityManagerFactory</code> for which I can create one (or multiple) <code>EntityManager</code> instances. I'm using a Servlet environment, and I've got one EntityManagerFactory wired up to the servlet (via the servlet context) which is shared for the lifetime of the servlet (and therefore, for all users).</p>
  
  <p>I can do one of the following:</p>
  
  <ul>
  <li>Create a single EntityManager for the lifetime of my servlet (e.g. shared between all users)</li>
  <li>Create one per user (so each user gets their own in the HttpSession)</li>
  <li>Create one per HTTP request (say, by instantiating a new one and closing it at the end of a <code>doGet</code> method)</li>
  </ul>
  
  <p>Which is most appropriate? Is the cost of creating an EntityManager significant?
  If I do a single shared EntityManager, is there a single transaction scope (i.e. updates between independent users could commit others changes)?</p>