title: Tips for Manually Managing Persistence Context
body: <p>I am investigating using JPA for my Data Access code.  I am trying to write the business layer and data access layer so it will work in a web application and a Java SE application.  Therefore I cannot use container managed persistence context.  Most of my seraches on using JPA show examples in a container managed enviroment.</p>
  
  <p>At the moment I get the EntityManagerFactory everytime I create a new instace of the service class.  For every operation (ie add, get, etc) I open an EntityManager, start a transaction perform operations, commit and then close the EntityManager and the EntityManagerFactory.  I would like the benifits of having a manged persistence context outside of the Java EE environment.  </p>
  
  <p>Are there any best practices when not using a container managed context?  Are there any Java EE independent persistence context managers?  Are there any recommended patterns?  </p>
  
  <p>Thanks,</p>
  
  <p>Al</p>
  
  <p><strong>Update</strong></p>
  
  <p>Thank you eveyone for the info.   Everything was very useful.</p>