EcipseLink JPA 2.0 是否需要refresh()/flush()?

发布于 2024-12-21 13:57:46 字数 456 浏览 3 评论 0原文

当有 150 多个用户连接到我们的 Web 应用程序时,我的数据库返回的数据不一致,这很奇怪。

我的 EJB 主要通过 Netbeans 7.0 生成的代码连接到 MySQL,并为可重用性进行了一些定制。发生的情况是,用户(在浏览器中)经常收到不正确的数据。即用户正在查看产品A的详细信息,但部分数据(一些一对多关系数据)属于不同的产品。当登录用户较少时,我们不会出现此问题。大约 150 个用户似乎开始出现问题。

代码的 EntityManager 部分仅执行 em.create(...)em.persist(...)em.merge(...)。没有 refresh()flush()。我禁用了共享缓存。我没有负载平衡。

我可以在哪里查看更多内容?

I have weird behavior of inconsistent data returned from my DB when there are 150+ users connected to our Web-app.

My EJBs connect to MySQL through mostly Netbeans 7.0 generated code, customized a bit for re-usability. What happens is that every so often, a user receives (in the browser) data that is not what it should be. I.e. User is viewing the details of product A, but part of the data (some one-to-many relationship data) belong to a different product. We don't have this issue when less users are logged-in. It seems problems start to raise at about 150 users.

The EntityManager part of the code does only em.create(...), em.persist(...) or em.merge(...). There is no refresh() or flush(). I disabled the shared cache. I have no load balancing.

What/Where could I look more?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情深已缘浅 2024-12-28 13:57:46

这取决于你的情况。

但供您参考,以防您想使用这些方法:

refresh() 使用数据库表中的数据更新实体。

flush() 的作用恰恰相反,将实体中的值保存到数据库表中。

但由于您使用的是 EJB,如果您使用 CMP,则默认情况下 EJB 中的所有方法都在事务中运行(除非提供了事务属性以不使用它们)。事务从方法调用开始,到方法完成时结束。最后它被提交,这意味着您不需要调用flush()。但是如果您需要在提交之前将数据库与实体同步,那么您需要调用flush()

除此之外,这实际上取决于您的要求是什么。

It depends on your situation.

But for your information in case you want to use those methods:

refresh() updates the entity with the data in the database table.

flush() does the exactly opposite, saves the values in the entity to the database table.

But since you are using EJBs, if you are using CMP then by default all the methods in an EJB run in a transaction (unless the transaction attributes are provided to not use them). And the transaction begins with the method call and ends when the method is done. At the end it is committed, which means you don't need to call the flush(). But if you need to synchronize the database with the entity before the commit then you need to call the flush().

Other than that it really depends on what your requirement is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文