谷歌应用程序引擎 (Java) + Spring管理的PersistenceManager
我在 JDO 持久性刚刚检索到的对象列表方面遇到了一些问题。
我想做的是:
- 获取“订单”列表
- 修改一个属性“状态”
- 对“订单”进行批量更新
到目前为止我得到的是 “具有 id 的对象...由不同的管理对象管理器”。 但是等等,如果没有 Spring,我还没有遇到过这样的问题!
我尝试像这样调试它:
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 不执行任何操作,只是:
try {
System.out.println(getPersistenceManager().hashCode());
getPersistenceManager().makePersistentAll(entities);
} finally {
getPersistenceManager().close();
}
我的所有 DAO 都扩展了 JdoDaoSupport。 Pmf 由 spring 注入和管理。
最后,问题来了:为什么findByIdAll之后持久化管理器关闭了?或者为什么我会得到新的持久性管理器实例?当然,我的 findByIdAll 方法不会调用持久性管理器上的 close 。
当然,如果我为每个“订单”调用 makePersistent ,效果会很好。但它打破了业务和数据库逻辑的分层......
UPD 刚刚发现迁移到 spring 管理的 PersistenceManager 后,所有对 makePersistentAll 的调用都不起作用。在春天之前,我使用了普通的旧 PMF.get() 助手,一切都闪闪发光!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的应用程序响应 HTTP 请求而保持活动状态的时间超过 30 秒,它将被终止。 GAE 运作模式的一部分是您的应用程序寿命不长。完全没有。
尽管您不会在自己的站点上执行此操作,但您必须习惯于只能短期访问数据库会话管理器。有时需要花费大量时间来为每笔交易重新打开它,但这就是 GAE 使流程可扩展的方式。如果你确实有很多流量,它可以在多台服务器上并行运行你的应用程序。
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.
这有点神奇。每次我在这里问问题时,我都会在发布后 24 小时内知道问题的答案。
当然,工厂顾名思义应该总是创建一个新的 pm 实例。现在我保存对我的旧 pm 的引用(就像我在 spring jdo daos 之前所做的那样),一切都很好。
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.