How to access previous Entity state?

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.

+4
source share
1 answer

Roolback does not return the object to its previously updated / previously saved state; it returns any changes to the database. I think there is no such object in contex.I think constancy. I think you should use the aspect.

0
source

Source: https://habr.com/ru/post/1386637/


All Articles