Hibernate无法验证ZonedDateTime

时间:2015-11-19 20:51:51

标签: java spring hibernate

我的课程中有这个参数:

@Past
private ZonedDateTime activityDate;

尝试保存到DB时,抛出以下异常:

javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.time.ZonedDateTime.
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.verifyResolveWasUnique(ConstraintValidatorManager.java:218)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.findMatchingValidatorClass(ConstraintValidatorManager.java:193)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.getInitializedValidator(ConstraintValidatorManager.java:97)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:125)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:91)
    at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:83)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:547)

任何人都可以解释为什么会这样,有没有办法让这个工作?或者我是否需要手动验证ZonedDateTime?

为了确保我在我的类路径中同时拥有org.hibernate:hibernate-core:5.0.3.Final和org.hibernate:hibernate-java8:5.0.3.Final,它们是目前最新的。

1 个答案:

答案 0 :(得分:0)

R4J的评论让我得到了正确的答案。它抛出了异常,因为我的类路径上没有hibernate-validator(或任何Validator接口)。添加最新版本对我有用,我发布此更新以防其他人犯同样的错误。