| First, lets discuss annotation binding and access types. You are using property-access because you're annotating your getter/setter methods. This binding strategy in conjunction with any smart getter/setter method with business or validation logic is typically taboo. What happens if some backend process updates a row, sets a value to some unexpected content, and your setter's business logic fails? This combination of binding strategy and domain-logic or validation can lead to potential problems, regardless of persistence provider. If you must leverage any logic inside your getter/setter methods, it is typically suggested that you use field-access by annotating the fields instead. Secondly putting access type aside, you assume that all non-primitive fields of an audited entity have no default non-null value. Unfortunately that is not always the case and Envers simply cannot operate under that assumption. As an entity instance is hydrated from audited data, the audited field setters must be invoked so that the appropriate value is set on the instance, clearing any potential default values, even if the value being set is null and the revision-type is DEL. A few immediate suggestions I have may be:
- Change from property-access to field-access to retain your setter logic.
- Leverage bean validation annotations instead to control your validation checks rather than putting this inside your setters.
|