Javax.validation.UnexpectedTypeException: No validator could be found for type:

hibernateintegerjavavalidation

the below is error we are getting when we try to put validation for size and pattern for Integer type.
can you suggest, we need to set the size and pattern validation for Integer type in validator bean.xml

05:58:57,342 ERROR [ErrorLoggerEJBInterceptor] Unexpected system error: No validator could be found for type: java.lang.Integer
javax.validation.UnexpectedTypeException: No validator could be found for type: java.lang.Integer
        at org.hibernate.validator.engine.ConstraintTree.verifyResolveWasUnique(ConstraintTree.java:244)

Best Solution

I'm just reading up on this, but could it be that type Integer cannot be applied to the Pattern constraint? It would explain why an UnexpectedTypeException is thrown, as it is only thrown if the type annoted does not match the constraints specification.

I found the following for the Pattern constraint for EE7: "The annotated CharSequence must match the specified regular expression. The regular expression follows the Java regular expression conventions see Pattern. Accepts CharSequence. null elements are considered valid."

src: http://docs.oracle.com/javaee/7/api/javax/validation/constraints/Pattern.html


In EE6 it seems to be limited to String: "The annotated String must... Accepts String. null elements are considered valid."

src: http://docs.oracle.com/javaee/6/api/javax/validation/constraints/Pattern.html


example:

@Pattern(regexp = "<insert regex here>")
Integer evaluateMe;

This should result in an UnexpectedTypeException as the Pattern constraint expects a CharSequence (EE7) or String (EE6), but finds type Integer.



After typing this I read Sridhar DD's reference, which confirms it :)