Hibernate: "ClassNotFoundException: javax.persistence.spi.ProviderUtil"

11,956

Solution 1

Do you have the correct JPA jar in your classpath? since youre error is: java.lang.NoClassDefFoundError: javax/persistence/spi/ProviderUtil

EDIT

Y'know, before we go further trying to figure this out, we should ask if it's really necessary to be using 3.5.0 (since at the time of this writing, it's 3.5.0-Beta-2). If all you're looking for is Annotations, using Hibernate Core 3.3.2 is enough to allow you to use Hibernate Annotations 3.4.0.

IMHO, you might want to just back up a version to something "safe"

Solution 2

If you are using Hibernate 3.5.x, you also need the following jar file.

hibernate-jpa-2.0-api-1.0.0-CR-1.jar

I had the same problem and adding this fixed the issue.

Solution 3

I don't know what documentation you are referring to as you didn't post any link so I didn't check what it is saying but I think that you you are missing the jpa-api dependency that I can see in the pom.xml of hibernate-parent-3.5.0-Beta-2 (it provides javax.persistence.spi.ProviderUtil):

<dependency>
  <groupId>org.hibernate.java-persistence</groupId>
  <artifactId>jpa-api</artifactId>
  <version>2.0-cr-1</version>
</dependency>

You can get it from the JBoss Maven repository (it doesn't seem to be included in the bundle released on SourceForge). Time to start using maven :)

Share:
11,956
Steve
Author by

Steve

Updated on June 05, 2022

Comments

  • Steve
    Steve almost 2 years

    My application is trying to use Hibernate annotations. I've gotten the 3.5.0 version of Hibernate installed, but when I try to load my app I get the following exception:

    junit.framework.AssertionFailedError: Exception in constructor: testSubscriber (java.lang.NoClassDefFoundError: javax/persistence/spi/ProviderUtil
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
        at java.lang.Class.getConstructor0(Class.java:2699)
        at java.lang.Class.newInstance0(Class.java:326)
        at java.lang.Class.newInstance(Class.java:308)
        at javax.persistence.Persistence.findAllProviders(Persistence.java:79)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
        at com.upod.dao.SubscriberDAOTest.<init>(SubscriberDAOTest.java:32)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at junit.framework.TestSuite.createTest(TestSuite.java:58)
        at junit.framework.TestSuite.addTestMethod(TestSuite.java:280)
        at junit.framework.TestSuite.<init>(TestSuite.java:140)
        at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:102)
        at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:59)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: java.lang.ClassNotFoundException: javax.persistence.spi.ProviderUtil
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:254)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:399)
        ... 22 more
    )
        at junit.framework.Assert.fail(Assert.java:47)
        at junit.framework.TestSuite$1.runTest(TestSuite.java:90)
        at junit.framework.TestCase.runBare(TestCase.java:130)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:120)
        at junit.framework.TestSuite.runTest(TestSuite.java:230)
        at junit.framework.TestSuite.run(TestSuite.java:225)
        at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    

    Apprently, I'm missing something, or I have incompatible jars again, but for the life of me I can't figure out where the problem is. I've got the hibernate3.jar, ejb3-persistence.jar, and all of the dependencies specified in the Hibernate docs, yet I still get this.

  • Steve
    Steve over 14 years
    The only JPA jar I know of is the ejb3-persistence.jar, and I do have it on my classpath. The class that is not found is not defined in that jar.
  • dustmachine
    dustmachine over 14 years
    Hmmm, where did that ejb3-persistence.jar come from? is it JPA 2.0 ?
  • Steve
    Steve over 14 years
    Near as I can tell, that jar is necessary to define the annotations for a JPA application. If I remove it, I get compile errors for @Entity, etc...
  • Steve
    Steve over 14 years
    Actually, its not necessary to use 3.5.0, but when I went back to the 3.3.2 version I got other missing classes (ReflectionManager I believe was one of them). I used 3.5.0, since it seemed that all the dependencies were included so there was less chance of me missing a jar file :-)
  • Steve
    Steve over 14 years
    Ok, so I moved back to the 3.3.2 version. When I run my testcases now, I get an exception saying that org.hibernate.annotations.common.reflection.ReflectionManage‌​r is not found. Same problem, different jar...
  • dustmachine
    dustmachine over 14 years
    well that one can be solved by including hibernate-commons-annotations jar. -- Are you using Maven by any chance?
  • Steve
    Steve over 14 years
    I found the hibernate-commons-annotations.jar and included it. Tha solved the hibernate problems. Unfortunately, I'm still having other class path issues, but I'll wade through those and see if I can't figure them out... Thanks for the help...
  • James McMahon
    James McMahon about 14 years
    Steve, see Srini's answer, stackoverflow.com/questions/1821553/…. This import is needed for the new version of Hibernate.