PostUpdateEvent postUpdateEvent = (PostUpdateEvent) event; Field fields = postUpdateEvent.getEntity().getClass().getDeclaredFields(); String propertyNames = postUpdateEvent.getPersister().getEntityMetamodel().getPropertyNames(); Object newStates = postUpdateEvent.getState(); Object oldStates = postUpdateEvent.getOldState();
Edits: As part of this there are few queries, on the gaps i have in my understanding. With respect to hibernate, there are three states: 1.Transient 2.Persistant 3.Detached
If we create a new object, it is transient state. Now when we do update or saveorupdate or merge with the hibernate session, then the object becomes persistent.
In this scenario, if we use hibernate postupdateevent to capture the updates, we are getting the old values only when we use merge and we dont get the values when we use update, or saveorupdate. My understanding was saveorupdate also does get call to determine if it is insert or update, in such cases i was expecting it to give old values in hibernate postupdate event when we do saveorupdate similar to what we get when we do merge. But we dont get for saveorupdate and update calls, we just get the old values for merge.
It sounds like the postupdateevent listener if we use for audit logs, with saveorupdate or update, it wont give us the old values.
Am i missing something here?