Hibernate version: Hibernate 3.2.6, annotations 3.3.1 and entitymanager 3.3.2
L2 Caching disabled
Name and version of the database you are using: Postgres 8.2
I have two entities:
Parent and child, with parent.children as a OneToMany relationship to child.
A parent and all its children are read by one EntityManager and transaction (EM1). FWIW, no changes are made to the parent or children.
While that transaction is still open, another process removes one of the children.
I cannot find how to refresh the parent into the first EntityManager EM1:
em1.find(Parent.class, parent.getId()) just returns the cached copy (complete with
em1.refresh(parent) throws an EntityNotFoundException, referring to the deleted child [Also known as a UnresolvableObjectException]
((HibernateEntityManager)em1).getSession().evict(parent) throws
org.hibernate.PersistentObjectException: detached entity passed to persist [probably because I don't have any hibernate-specific/evict cascades]
So, my questions are:
Should just plain old em.refresh( parent ) refetch a new list of children? If so, I'll be happy to post many more details about my entities, logs, etc to figure out why it is not working for me.
If em.refresh() is not expected to work, is there a way to get an updated parent into its existing EntityManager?
Do I need to create a new EM and just read the parent from scratch?
Thanks much,
Bert
|