It's very frecuent in business application to write not reusable validations. In this case, if we force the developer to write an annotation for each validation, in addition to the java code for the validation; we are adding bureaucratic work for the developer.
My suggestion is to include a built in constraint in JSR-303 called @Constraint, @Validator, @GenericConstraint or so, that can be used in this way:
Code:
@Validator(InvoiceConstraint.class)
public class Invoice {
...
}
Where InvoiceConstraint implements Constraint.
Because the validation logic for Invoice can be used only on Invoice, we do not need to define an annotation for it, only the class, therefore you will save a lot of bureaucratic code.
This is in the spirit of the @ProperyValidator
http://openxava.wikispaces.com/model_en#toc11
and @EntityValidator
http://openxava.wikispaces.com/model_en#toc19
annotations of OpenXava
What do you think ?