I am trying to detect changes in Entity in order to detect changes made to an object so that I can log make changes made for any user.
To date, I have managed to use:
@EntityListeners(AuditListener.class) @Entity public class Entity1{...}
and
public class AuditListener { @PostPersist @PostUpdate public void setUserInformation(Object entity) {...} }
Now, what I would like to have is a way to read the Previous state of the object, so I can compare it with the current values ββand write the fields, new values ββand the user who made the changes to the audit table.
I know that I can use @PostLoad and keep the previous state in memory, but I think there should be a more general way to do the same (less hard-coded).
Thanks in advance.
source share