I having a spring method: where I am validating the entity after constructing of object, which was previously fetched from DB.
@Transactional(rollbackFor={ValidationException.class})
public Object approve(Command command) throws ValidationException {
Object obj = merger.mergeWithExistingobject(command); // where I am fetching object from DB with old values and construct the new object
validatorService.validate( obj ); // which throws ValidationException
return saveObject(obj);
}
But unfortunately even after the ValidationException was thrown. The values still get persisted in DB. How can I avoid this situtation.
mergeWithExistingobject?validatorServiceunder spring control ? PostValidatorServicecode please.