google-app-engineservletsopen-session-in-viewpersistence-manager

PersistenceManager and Open Session In View


my java skills are a bit rusty and I'm wondering how I can implement Open Session In View pattern for the PersistenceManager called from a servlet in a google app engine environment.

I have some singleton which handles the PersistenceManagerFactory, but how can I get a "new" PersistenceManager at each servlet call ?

I want my business class to access some repository that will use the same PersistenceManager, and that all the time (within one servlet request).

For now, I can't figure out how to initialize a new PersistenceManager when the first call to the singleton is made, for each servlet request...

Thanks in advance for any help.


Solution

  • Don't. Pass the PersistenceManager to your class as part of the context, instead. Relying on statics or globals is usually a bad idea, especially in a multithreaded environment like a Java servlet.