Friday, June 7, 2013

Use @ScriptAssert logic With a Field Error

The new @ScriptAssert validator by Hibernate can be really useful for throwing together a quick validation rule that spans over several bean properties, but one of the short comings is that you can't specify a field level error.

 So here is a solution to that. You'll probably notice it doesn't extend the script assert logic, it duplicates it. That's because you can't inherit from an annotation.


  1. Hello, could you share contents of ConstraintValidatorUtils as well?

    1. Already found it..

  2. Why your solution is useful is also this:

    If you specify both @ScriptAssert and some other validation annotations at bean level (say @NotNull), if @ScriptAssert evaluates to 'true' @NotNull gets ignored fully. That is, an ivalid bean gets reported as valid because @ScriptAssert was used.

  3. Hi Brett, that's a great idea. I think it should be supported by the original @ScriptAssert, so I've filed an issue in our tracker ( Should be part of one of the next releases.