HV000030: No validator could be found for type: java.lang.Long(解决)

在使用hibernate validator后台校验时出现如下错误

javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.lang.Long.
    at org.hibernate.validator.internal.engine.ConstraintTree.verifyResolveWasUnique(ConstraintTree.java:411)
    at org.hibernate.validator.internal.engine.ConstraintTree.findMatchingValidatorClass(ConstraintTree.java:392)
    at org.hibernate.validator.internal.engine.ConstraintTree.getInitializedValidator(ConstraintTree.java:350)
    at org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:171)
    at org.hibernate.validator.internal.engine.ConstraintTree.validateComposingConstraints(ConstraintTree.java:259)
    at org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:154)
    at org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:124)
    at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:85)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:463)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForNonDefaultGroup(ValidatorImpl.java:436)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:367)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:322)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:152)
    at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:108)
    at org.springframework.validation.DataBinder.validate(DataBinder.java:781)

原因是在实体类Long类型的属性使用了@NotEmpty

@NotEmpty
private Long roleId;

需要改成@NotNull

@NotNull private Long roleId;

参考资料:http://blog.csdn.net/dracotianlong/article/details/23181729

需要注意@NotEmpty不能用于Long Integer 等基础数据类型,需要使用@NotNull

来源://作者:/更新时间:2015-04-21
相关文章
评论:
验证码:
匿名评论:

最新文章

文章排行