eclipselink从数据库中删除记录
我有代码:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论