title: GWT RequestFactory: how to use single EntityManager per request
body: <p>In order to get <code>RequestFactory</code> to <a href="https://stackoverflow.com/questions/4973440/gwt-requestfactory-not-persisting-attached-entities">persist attached entities</a>, I need to ensure that I use the same <code>EntityManager</code> for each request. </p>
  
  <p>I cobbled together my own Factory class for this based on a <code>ThreadLocal</code> implementation, but I'm unsure how to properly release resources (e.g. how to know that the request has finished and call <code>close()</code>).</p>
  
  <p>Is there a simple way to ensure that a single EntityManager is used throughout a given ServletRequest without resorting to full-on J2EE/CDI? I'll take that route if I must, but I was hoping to keep things simple, especially since I'd like to continue using the lightweight development server that comes with GWT.</p>