eclipselink从数据库中删除记录

发布于 2025-02-11 05:01:21 字数 1358 浏览 0 评论 0原文

我有代码:

public EntityManager getEntityManager() {

EntityManagerFactory emf = Persistence.createEntityManagerFactory("my-app");
EntityManager em = emf.createEntityManager();

return em;

}
for (...) {
  EntityManager em = getEntityManager();
 
  ...creating myEntity
 
  for (...) {
    em.getTransaction().begin();
    entityManager.persist(myEntity);
    em.getTransaction().commit();
  }
 
}

问题:我在上午8点运行此代码,然后在数据库上看到记录。 9小时后,当我运行代码时,从凌晨8点开始删除记录,

您可以告诉我是否对:

  • 即使对EM的参考总是不同的参考,也只有一个持久性上下文。
  • 默认情况下,在交易期间尚未修改或删除的托管实体对象在持久性上下文中通过弱参考
  • 在这9个小时的垃圾收集器中删除了以前的实体,
  • EM没有“看到” Entites antites and entites,并且从DB中删除了记录,

这是此解决方案正确的?

add => em.clear();

for (...) {
  EntityManager em = getEntityManager();
 
  ...creating myEntity
 
  for (...) {
    em.getTransaction().begin();
    entityManager.persist(myEntity);
    em.getTransaction().commit();
  }
 
  em.clear(); 
}

我发现这个=

“ nofollow noreferrer”> http:> 3f

所以,当我添加此=时,我的解决方案将可以。

<property name="eclipselink.cache.shared.default" value="false"/> 

I have the code:

public EntityManager getEntityManager() {

EntityManagerFactory emf = Persistence.createEntityManagerFactory("my-app");
EntityManager em = emf.createEntityManager();

return em;

}
for (...) {
  EntityManager em = getEntityManager();
 
  ...creating myEntity
 
  for (...) {
    em.getTransaction().begin();
    entityManager.persist(myEntity);
    em.getTransaction().commit();
  }
 
}

The problem: I run this code 8 AM , and I see records on database. When I run the code 9 hours later the records from 8AM are deleted

Could you please tell me if I am right:

  • Even though there is always different reference to EM , there is only one persistence context.
  • By default, managed entity objects that have not been modified or removed during a transaction are held in the persistence context by weak references
  • During these 9 hours garbage collector removed previous entities
  • EM did not "see" entites and deleteded records from DB

Is this solution correct?

add => em.clear();

for (...) {
  EntityManager em = getEntityManager();
 
  ...creating myEntity
 
  for (...) {
    em.getTransaction().begin();
    entityManager.persist(myEntity);
    em.getTransaction().commit();
  }
 
  em.clear(); 
}

I found this =

http://wiki.eclipse.org/EclipseLink/FAQ/How_to_disable_the_shared_cache%3F

So, my solution is going to be OK when i add this =

<property name="eclipselink.cache.shared.default" value="false"/> 

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文