且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除列表中的项目后如何更新列表

更新时间:2022-01-30 10:53:35

您所写的内容是正确的,重新查询应该可以工作(实际上是通常的工作方式),因此问题必须出在其他地方.例如,如果您通过除remove方法以外的任何其他方式删除实体,则该实体可能仍位于第二级缓存中.还是因为一些小错误而根本没有发生重新查询?

What you have written is correct, requerying should work (and in factis how it's usually done), so the problem must be somewhere else. For example if you delete the entity by any means other than the remove method, it may still be in the 2nd level cache. Or maybe the requerying does not happen at all because of some small mistake?

更新:阅读了原始问题的新版本(包括所有新资源和有关Eclipselink的说明)后,我做了一点测试,这确实是第二级缓存问题.有点奇怪,可能是错误或未指定的特殊情况.要解决此问题,请从缓存中逐出注释:

Update: After reading the new version of the original question (with all the new sources and clarification about Eclipselink) I made a little test, and it is - indeed - a second level cache problem. A bit strange, and possibly either a bug or an underspecified corner case. To fix it, evict comments from cache:

// this goes after em.remove(e)
em.getEntityManagerFactory().getCache().evict(Comment.class);

您还可以尝试仅驱逐已删除实体的父级(存在逐出的超载版本).

You could also try evicting the parent of the removed entity only (there is an overloaded version of evict).

嗯.也许有更多街头信誉(BalusC?:-)的人应该更改此帖子上的标签.事实证明,它与JSF没有任何关系.

Uhmpf. Maybe someone with more street cred (BalusC? :-) should change tags on this post. Turned out it has nothinh to do with JSF.