Search code examples
javamavenhibernate-validator

NoClassDefFoundError while using hibernate-validator


I have a mavenized project, where I use JSR 303 (Bean validation). As reference implementation I use Hibernate-validator. In project I specified dependency:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>4.1.0.Final</version>
    <scope>provided</scope>
</dependency>

With version 4.1.0 all works fine. But when I change it to 4.2.0. I get runtime error on this line:

ValidatorFactory factory = Validation.buildDefaultValidatorFactory();

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence

......//more stack-trace

java.lang.NoClassDefFoundError: Could not initialize class com.andr.myproject.services.utils.ValidationUtils

Where is problem?

UPD: Also I use Java-ee-5 dependency, not 6.

UPD2: this error occurs in JUnit test


Solution

  • I found solution:

    I need to add hibernate-core dependency. Without it it wouldn't work.

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.0.1.Final</version>
        </dependency>