I am trying to implement an entitylistener that compares the original and the updated object in the @PreUpdate event. I tried to use the Jpa Repository to query the original object by Id from DB to compare it with the object received in the event. But it retrieves the same object (i guess it returns the object present in the session scope).
Is there a way to get the original object from the database in the entity listener?
JPA does not provide the old and new state in the EntityListener.
But you can use Hibernates interceptors:
In this example you see that you the the current and the previous state as arrays that can be easily compared.
Please read the docs: https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#events