I am not sure it/there is a "right" way, but in my application I am
injecting (via Spring)
a (singleton) PMF into my Controller(s) (which are singletons) and
instantiating a PM for each (concurrent) query/request...

On Dec 4, 11:30 pm, Fan Lin <linfa...@gmail.com> 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.


Reply via email to