Upon testing this in action, I believe I'd rather see a few slight changes. First, the RelationTargetNotFoundAction enum will maintain 3 values rather than 2:
public enum RelationTargetNotFoundAction {
DEFAULT,
ERROR,
IGNORE
}
Secondly, the Audited annotation will use a different default:
public @interface Audited {
/**
* Specifies if the entity that is the target isn't found how should we react.
* The default is to ignore the failure if the target entity doesn't exist.
*/
@Incubating
RelationTargetNotFoundAction targetNotFoundAction() default RelationTargetNotFoundAction.DEFAULT;
}
Lastly, the configuration property:
/**
* Specifies whether the legacy not-found behavior of throwing an EntityNotFoundException should be used.
* Defaults to {@code true}.
*/
String GLOBAL_RELATION_NOT_FOUND_LEGACY_FLAG = "org.hibernate.envers.global_relation_not_found_legacy_flag";
What this leads to is that users upgrading to 6.0 will see no change in behavior. The EntityNotFoundException will continue to be thrown without users having to make a single change to their classes, annotations, or configurations. This allows easy backward compatibility but flexibility for users to engage in the new behavior as needed. So in order to actually ignore these EntityNotFoundException cases, users have several options. The first is to enable the feature globally. Users can do that by changing the org.hibernate.envers.global_relation_not_found_legacy_flag to false. In other words, the default enum value of DEFAULT directly translates to whether legacy behavior is ON or OFF based on the configuration setting. The second option is to enable the feature for a specific entity class by specifying the targetNotFoundAction attribute at the class level's @Audited annotation. This means if the property uses the DEFAULT value but the class specifies IGNORE or ERROR, the properties will use the value defined at the class level. The only exception is for cases where your property defines itself explicitly as IGNORE or ERROR and then the class-level value won't have precedence. And obviously the third is to enable the feature by specifying the targetNotFoundAction attribute at the property level's @Audited annotation as mentioned above. Users can also mix-n-match the global configuration property & annotation values as needed to address their individual needs. |