title: NoClassDefFoundError in JPA 2.1
body: <p>I am getting a java.lang.NoClassDefFoundError: org/hibernate/service/classloading/spi/ClassLoaderService Exception</p>
  
  <p>I am using maven 4, jpa 2.1, hsqldb. am i missing something in my pom. i can add it if needed.
  it fails in unit tests, maven etc. I have no clue why. when i run it at home, it runs fine without exceptions. please help me in solving this problem</p>
  
  <p>persistence.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
           http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
  version="2.1"&gt;
  
  &lt;persistence-unit name="defaultUnit" transaction-type="RESOURCE_LOCAL"&gt;
  
  
      &lt;class&gt;com.core.Master&lt;/class&gt;
      &lt;class&gt;com.core.Child&lt;/class&gt;
  
      &lt;properties&gt;
          &lt;property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" /&gt;
          &lt;property name="hibernate.connection.url" value="jdbc:hsqldb:mem:myTestDb" /&gt;
          &lt;property name="hibernate.connection.username" value="sa" /&gt;
          &lt;property name="hibernate.connection.password" value="" /&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" /&gt;
          &lt;property name="hibernate.show_sql" value="false" /&gt;
          &lt;property name="hibernate.hbm2ddl.auto" value="create-drop" /&gt;
  
          &lt;!-- insert data using sql file --&gt;
          &lt;property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/&gt;
          &lt;property name="javax.persistence.schema-generation.create-source" value="metadata"/&gt;
          &lt;property name="javax.persistence.schema-generation.drop-source" value="metadata"/&gt;
          &lt;property name="javax.persistence.sql-load-script-source" value="import.sql"/&gt;
  
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>when i run the following line:</p>
  
  <pre><code>    entityManagerFactory =  Persistence.createEntityManagerFactory("defaultUnit"); 
  </code></pre>
  
  <p>it throws exception as below</p>
  
  <pre><code>    java.lang.NoClassDefFoundError: org/hibernate/service/classloading/spi/ClassLoaderService
  at org.hibernate.envers.event.EnversIntegrator.integrate(EnversIntegrator.java:65)
  at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:312)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
  at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397)
  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
  at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75)
  at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
  at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
  at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
  at com.jpa.generator.EntityManagerGenerator.create(EntityManagerGenerator.java:12)
  at com.core.TestMaster.testSqlInsert(TestMasterContainer.java:81)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:483)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
  at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
  at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
      Caused by: java.lang.ClassNotFoundException: org.hibernate.service.classloading.spi.ClassLoaderService
  at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  ... 37 more
  </code></pre>
  
  <p>pom.xml</p>
  
  <pre><code>        &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;5.1.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
          &lt;version&gt;1.0.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
          &lt;version&gt;5.1.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
              &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
          &lt;version&gt;1.7.5&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
          &lt;version&gt;1.7.5&lt;/version&gt;
      &lt;/dependency&gt;  
      &lt;dependency&gt; 
          &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
          &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
          &lt;version&gt;2.3.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;4.9&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  </code></pre>