It will take a moment for me to explain this, so please stay with me. I have table NewsFeed
that has OneToMany relationship with itself.
@Entit
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?
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).
Uhmpf. Maybe someone with more street cred (BalusC? :-) should change tags on this post. Turned out it has nothinh to do with JSF.
When you delete an object you must remove all reference to that object before deleting it. If you do not, you can get a constraint error, or stale data in your persistence context, or in the 2nd level cache.
When removing the Feed, first remove it from the replies.