2007/11/5, Marc Siegel <[EMAIL PROTECTED]>: > Thanks for the input. I am not operating inside an explicit EJB > context or application server, but rather using OpenJPA in a regular > J2SE application as a persistence layer. > > In other words, I manage the scope of my own transactions and my > entityManager lifecycles.
Understood. What I suggested was to do it like EJB would do. > My transactions I understand how to scope. How should I scope the > EntityManager? That certainly is the tricky question. Thinking of client requests I would have a transaction and a new persistence context per request. If you do not use EJB I would recommend Spring transactions as they allow you to declaratively specify which method should run inside a transaction. Spring will take care of the rest. HTH Oliver > On 11/5/07, Oliver Zeigermann <[EMAIL PROTECTED]> wrote: > > AFAIK in an EJB context the EM is closed when a transaction is ended. > > Unless you configure an extended persistence context. In that case the > > EM stays open even when a transaction is commited and will be closed > > upon removal of the EJB that holds it. > > > > Oliver > > > > 2007/11/5, Marc Siegel <[EMAIL PROTECTED]>: > > > Hi Folks, > > > > > > Is it necessary to close the EntityManager and open a new one to avoid > > > memory leaks / excessive usage? What is the best practice for > > > EntityManager lifecycle? > > > > > > -Marc > > > > > >
