开发者

Google App Engine (Java) + Spring managed PersistenceManager

I've got kinda problem with JDO persistence of a list of just retrieved objects.

What I want to do is to:

  • Fetch list of "Orders"
  • Modify one property "status"
  • Make bulk update of "Orders"

What I've got so far is "Object with id ... is managed by a different Object Manager". But wait, I haven't faced such a problem without Spring!

I tried to debug it like this:

List<Orderr> orders = orderDao.findByIdAll(ordersKeys);
for(Orderr o : orders) {
    System.out.println(JDOHelper.getPersistenceManager(o).hashCode());
    //hashcode is 1524670
    o.setSomething(somevalue);
}
orderDao.makePresistentAll(orders); //hashcode inside is 31778523

makePersistentAll does nothing but:

try {
    System.out.println(getPersistenceManager().hashCode());
    getPersistenceManager().makePersistentAll(entities);
} finally {
    getPersistenceManager().close();
}

All my DAOs extend JdoDaoSupport. Pmf is injected and managed by spring.

Finally, here is the question: Why is the persistence manager closed after findByIdAll? Or why do I get new persistence ma开发者_开发知识库nager instance? My findByIdAll method doesn't call close on persistence manager, of course.

Of course if I call makePersistent for each "order" it works well. But it breaks layering of business and database logic...

UPD Just found out that all calls to makePersistentAll aren't working at all after migration to spring managed PersistenceManager. Before spring I used plain old PMF.get() helper and everything was shiny!


If your app remains live in response to a HTTP request for longer than 30 seconds, it will be killed. Part of the mode of operation of GAE is that your apps are not long-lived. At all.

Though you wouldn't do this on a site of your own, you'll have to get used to having only short-term access to your DB session manager. A lot of time is sometimes needed to re-open it for every transaction, but that's how GAE makes the process scalable. If you really have a lot of traffic, it can run your application in parallel on several servers.


This is kind of magic. Everytime I ask here a question I know the answer to my question within 24 hours after post.

Of course, factory by its meaning should always create a new pm instance. Now I save reference to my old pm (like I did before spring jdo daos) and everyting is ok.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜