I\'m trying to get the old entity in a @HandleBeforeSave event.
@Component
@RepositoryEventHandler(Customer.class)
public class CustomerEventHan
The following worked for me. Without starting a new thread the hibernate session will provide the already updated version. Starting another thread is a way to have a separate JPA session.
@PreUpdate
Thread.start {
if (entity instanceof MyEntity) {
entity.previous = myEntityCrudRepository.findById(entity?.id).get()
}
}.join()
Just let me know if anybody would like more context.