1
@Component
@RepositoryEventHandler
public class UserEventHandler {

    @HandleBeforeSave
    public void handleUserSave(User user) throws InterruptedException {
       User oldUser = userRepository.findById(user.getId());   //already too late, gets the new password
    }
}

I have a method that gets triggered before a User is saved by Spring Data Rest. I want to check the old and new password, for example to not let it to be the same.

But there is no way to query the old password by the time the handler is called, even though the database still has the value.

How to solve this?

erotsppa
  • 14,248
  • 33
  • 123
  • 181
  • Does this answer your question? [How to get old entity value in @HandleBeforeSave event to determine if a property is changed or not?](https://stackoverflow.com/questions/25233089/how-to-get-old-entity-value-in-handlebeforesave-event-to-determine-if-a-propert) – xerx593 Mar 10 '20 at 20:14
  • Hmm its relevant but as far as I can tell all 3 solutions he said does not work directly with Spring Data Rest. I dont operate hibernate directly at all in this project. – erotsppa Mar 10 '20 at 20:31
  • my link refers to an (currently) open bug @spring-data, also the non-accepted and even 0pt. solutions provide "credible" workarounds. (i still tend to +1&close) – xerx593 Mar 10 '20 at 20:47
  • ..the bug is ~6 years old (though "major")..and to [cite Tyler Eastman](https://stackoverflow.com/a/52957281/592355) >Spring Data Rest can't and likely won't ever be able to do this due... – xerx593 Mar 10 '20 at 20:55

0 Answers0