views:

501

answers:

2

Hi,

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 manager 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!

+1  A: 

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.

Carl Smotricz
Although I'm developing GAE app, it's not specific to it. I've got same thing on localhost SDK (nothing but Jetty). And I thought that, as you say, "DB session manager" is PersistenceManagerFactory but not PersistenceManager. I can get my old PersistenceManager from each object, but it's not the way I should do it. It means that it's not closed at all, but removed by spring from dao, I guess.
Vladimir Shulyak
Hmm. Then I think we've gone beyond my ability to help you. I used some Spring in a GAE app, but our relationship was not a happy one. Sorry, and good luck!
Carl Smotricz
Thank you! Yes, the question is not obvious one...
Vladimir Shulyak
A: 

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.

Vladimir Shulyak