Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate validator error - 4.0.2.GA

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(ValidatorImpl.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)
like image 262
Alexandre Dupuis Avatar asked Jan 22 '23 18:01

Alexandre Dupuis


2 Answers

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.

like image 111
Javi Avatar answered Jan 26 '23 11:01

Javi


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

like image 21
BoneGoat Avatar answered Jan 26 '23 10:01

BoneGoat