【发布时间】:2012-11-08 18:02:00
【问题描述】:
我在使用 JPA(使用 EclipseLink 4.2.1)时遇到了一个奇怪的问题。
相关部分代码:
l.debug("creating EM");
em = factory.createEntityManager();
int id = Integer.parseInt(idString);
l.debug("parsed");
em.getTransaction().begin();
SomeClass g = em.find(SomeClass.class, id);
l.debug("found");
em.remove(g);
l.debug("removed");
em.getTransaction().commit();
l.debug("Returning...");
输出是:
DEBUG - creating EM
DEBUG - parsed
DEBUG - found
DEBUG - removed
如您所见,最后一行没有显示(commit() 没有返回)。它不会抛出任何异常。但是,该对象已从数据库中删除。
在应用程序的任何其他点都没有这样的问题。
【问题讨论】:
-
死锁可能是根本原因。是否有其他东西同时运行?
-
感谢 Aksel,看起来确实出现了死锁。我想我修好了。如果您可以将其发布为答案,我很乐意接受。
-
你应该考虑使用适当的事务隔离级别
-
将 Eclipselink 日志打开到最好,因为这可能会显示更多关于它为什么挂起的信息,并在注意到它时获取线程转储,因为这将准确显示它被卡住的位置。
标签: java jpa persistence jpa-2.0 eclipselink