javax.validation.UnexpectedTypeException:找不到类型的验证器:

Sre*_*llu 4 java validation integer hibernate

以下是我们在尝试对Integer类型的大小和模式进行验证时得到的错误.你能建议吗,我们需要在验证器bean.xml中设置Integer类型的大小和模式验证

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)
Run Code Online (Sandbox Code Playgroud)

小智 5

我只是在阅读这篇文章,但可能是类型Integer无法应用于Pattern约束吗?它将解释为什么抛出UnexpectedTypeException,因为只有在annoted类型与约束规范不匹配时才会抛出它.

我发现EE7的Pattern约束有以下内容:"带注释的CharSequence必须与指定的正则表达式匹配.正则表达式遵循Java正则表达式约定,参见Pattern.接受CharSequence.null元素被认为是有效的."

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


在EE6中,它似乎仅限于String:"带注释的字符串必须...接受字符串.空元素被认为是有效的."

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


例:

@Pattern(regexp = "<insert regex here>")
Integer evaluateMe;
Run Code Online (Sandbox Code Playgroud)

这应该导致UnexpectedTypeException,因为Pattern约束需要CharSequence(EE7)或String(EE6),但是找到类型Integer.



输入后我读了Sridhar DD的参考文献,证实了它:)