My understanding is that the persistence manager factory can be a single instance that's shared, but the persistence manager, which the persistence manager factory produces, must not be shared. Your DaoBase can have a setter for the persistence manager factory, but not for the persistence manager. Each DaoBase method should use the persistence manager factory to get a persistence manager, and use that persistence manager for its database operations.
http://www.datanucleus.org/products/accessplatform_1_0/guides/jdo/daolayer_design.html Fan Lin wrote: > Hi, I'm new in JDO, so I think this problem may sounds stupid... > I'm working on my application on App-engine, and feel really confused > about how to use the PersistenceManager in my app... > > 1) At the very beginning I tried to maintain only one static pm > instance in my app, but I found that when I try to update the entities > in datastore, it does not write back, since I do not close the pm. > > 2) Then, I tried to get a new pm in every request, and after the > request I close it. But I still store the pm as a static field in a > DaoBase class. the code looks like: > > PersistenceManager pm = PFM.get().getPersistenceManager(); > DaoBase.setPm(pm); > > ....do the request... > > DaoBase.getPm().close(); > DaoBase.setPm(null); > > But when multiple requests come concurrently, things becomes messy and > sometimes the DaoBase.getPm() will returns null during a request. > > 3) Use new pm each time when reading the datastore, then detach the > object from pm, close the pm. Then during update time, use a new pm to > update it. But the problem here is when there is some owned > relationship between datastore entities, a detatched object will not > fetch the data automatically, like: > > ///////////////////////////// > class Address { > .... > } > > class Employee { > private List<Address> addressList; > > public List<Address> getAddressList() { > return addressList; > } > } > /////////////////////////////// > the getAddressList() will always return null. > > So...What is the right way to use PersistenceManager? > > > > -- > > You received this message because you are subscribed to the Google Groups > "Google App Engine for Java" group. > To post to this group, send email to google-appengine-j...@googlegroups.com. > To unsubscribe from this group, send email to > google-appengine-java+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/google-appengine-java?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-j...@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.