Given the following:
Code:
PersistentObject parent = new PersistentObject();
parent.setName("root");
PersistentObject child = new PersistentObject ();
child.setName("leaf");
child.setParent(parent);
parent.getChildren().add(child);
session.save(parent);
I get 2 records in the DB as expected and everything looks great. In particular, child.getParent()==parent evaluates to true. Then,
Code:
session.refresh(parent); // pick-up values set by triggers.
session.refresh(child); // pick-up values set by triggers.
Now child.getParent()==parent evaluates to false! A bit surprising. So, trying a lengthier approach:
Code:
session.evict(parent);
session.evict(child);
parent = session.load(PersistentObject, parent.getId());
child = session.load(PersistentObject, child.getId());
Once again child.getParent()==parent evaluates to false! Calling get() rather than load() produces the same result.
I thought Hibernate uniques the objects. Could someone explain what I'm missing/doing wrong.