Taking following code:
MyEntity e = dao.getEntity(1);
e.setProp1(someVal);
e.setProp2(otherVal);
MyEntity eOld = dao.getEntity(1);
If I do it like this then e will get updated (because Hibernate detected it is dirty) and eOld will have the same property values (prop1, prop2) a e. Is there a way to get the persisted state of this dirty entity (as it is in the database)?
Actually I may already have found the solution myself…
I had already tried evicting eOld but that doesn’t make since, I need to evict e before retrieving eOld and after the compare (for auditing) reattach (merge) e to the session again.
It seems to work in any case.