The basic example of using JDO in App Engine documentation is really simple:
PersistenceManager pm = PMF.get().getPersistenceManager();
Employee e = new Employee("Alfred", "Smith", new Date());
try {
pm.makePersistent(e);
} finally {
pm.close();
}
But in my opinion, it's kind of annoying to get and close persistence manager every time I want to access the storage, there's a lot of redundant code. So what would you recommend to avoid that?
For example, I came across a solution which recommended getting the PM in filter and attaching it to the request
so I could access it directly from any servlet. The PM would be closed by the filter automatically as well. What do you think?