4

I have next event handler:

@Component
@RepositoryEventHandler
public class EntityEventHandler {

    private final EntityService entityService;

    @HandleAfterSave
    public void handleAfterSave(final Entity entity) {
        // need old entity here to validate if specific field has changed
    }
}

Is there any way to get old entity in handleAfterSave ?

Orest
  • 6,548
  • 10
  • 54
  • 84
  • 1
    I normally simply store the previous state within the entity on load. Doesn't feel quite right but it's the most straightforward solution I've come across. https://stackoverflow.com/a/27531056/1356423 – Alan Hay Nov 16 '17 at 08:27
  • A bit ugly but yes that works! Thank you! – Orest Nov 18 '17 at 11:10
  • Possible duplicate of [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) – benkuly Nov 24 '17 at 14:38

0 Answers0