开发者

Hibernate validator error - 4.0.2.GA

开发者 https://www.devze.com 2022-12-15 23:55 出处:网络
the validate function of the Hibernate Validator seems to be buggy (version hibernate-validator-4.0.2.GA.jar). Do I maybe miss a dependency?

the validate function of the Hibernate Validator seems to be buggy (version hibernate-validator-4.0.2.GA.jar). Do I maybe miss a dependency?

Part of my stack trace:

java.lang.NoSuchMethodError: javax.persistence.Persistence.getPersistenceUtil()Ljavax/persistence/PersistenceUtil;
        at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:33)
        at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:112)
        at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:47)
        at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(Validato开发者_运维问答rImpl.java:764)
        at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:331)
        at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:278)
        at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:260)
        at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:213)
        at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)


I think it's due to the fact that it thinks you're using JPA2 but in fact you're using JPA1. Remove the jpa-api-2.0.Beta-20090815.jar which is included with the distribution of Hibernate Validator if you don't need it and try again.


This seems to be a bug which have been fixed in version 4.2.0.Beta1 of the Hibernate validator according to this Jira: https://hibernate.onjira.com/browse/HV-374

The stack trace is very confusing because it suggests that Java 5 is being used but I was certain that I was running Java 6.

I also did not have the option to update the validator and I was already running ejb3-persistence-1.0.2.GA.jar which is a proposed solution by @Gaim so I needed to create my own CustomTraversableResolver which forces JPA1. Details on how to do that are available here: http://soadev.blogspot.se/2010/02/jsr-303-bean-validation-error.html


I stuck on this issue today and made some digging on it. I found out @Javi's answer helpful but it didn't solve my problem. Another tens minutes of googling took me to find out the following:

Hibernate validator in version 4.0.2.GA (and probably also in the others) detects the version JPA by class javax.persistence.PersistenceUtil, because this class is NOT contained in JPA 1 but it is in JPA 2. Unfortunately some libraries implements this class what makes the Hibernate a bit confused. In such case it tries to use JPA 2 also in Java 1.5 environment which throws an exception mentioned in the question.

The solution is simple. Find out the library adding this class and remove it. In my case it was ejb3-persistence-1.0.1.GA.jar. This bug was reported long time ago and in version ejb3-persistence-1.0.2.GA.jar it is fixed. There so this upgrade solved the issue in my case.


Just now I found that there is a current dependency in java 6. Once i upgraded to java 6 all the errors above disappeared.

http://javaprogrammingtips4u.blogspot.com


Try adding ejb3-persistence 1.0.2GA to your class path/ maven pom:

<dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>ejb3-persistence</artifactId>
   <version>1.0.2.GA</version>       
</dependency>

There is a good explanation here: dependency-hell-or-including-jsr303


Try to upgrade to hibernate-validator 4.2 + version. I had the same issue with hibernate-validator 4.1.0 but when I upgraded to v 4.2.0 the issue gone

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-annotation-processor</artifactId>
        <version>4.2.0.Final</version>
    </dependency>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号