title: NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence
body: <p>I met the NoClassDefFoundError when initiating the HibernateJPAVendorAdapter</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaVendorAdapter' defined in class path resource [META-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence
  </code></pre>
  
  <p>I checked several threads on this exception but failed to find out the root cause of this. I think the initialization of JPAVendorAdapter has failed but not sure why. Maybe incompatibilities among my package dependencies, or in my applicationContext.xml. Here they are;
  pom.xml(only related sections included)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.canreef&lt;/groupId&gt;
      &lt;artifactId&gt;Calendar&lt;/artifactId&gt;
      &lt;version&gt;1.0&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;name&gt;Calendar&lt;/name&gt;
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;maven.compiler.source&gt;1.7&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;1.7&lt;/maven.compiler.target&gt;
          &lt;endorsed.dir&gt;${project.build.directory}/endorsed&lt;/endorsed.dir&gt;
  
          &lt;org.springframework.version&gt;4.0.1.RELEASE&lt;/org.springframework.version&gt;
          &lt;org.springframework.data.version&gt;1.7.0.RELEASE&lt;/org.springframework.data.version&gt;
          &lt;org.springframework.instrument.version&gt;4.1.1.RELEASE&lt;/org.springframework.instrument.version&gt;
          &lt;org.hibernate.version&gt;4.1.7.Final&lt;/org.hibernate.version&gt;
          &lt;jackson.version&gt;2.4.4&lt;/jackson.version&gt;
          &lt;external.resources&gt;${project.basedir}/src/main/lib&lt;/external.resources&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;4.3.1.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;4.3.0.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax&lt;/groupId&gt;
              &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
              &lt;version&gt;7.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;        
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
          &lt;/dependency&gt;        
          &lt;!-- Added--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
          &lt;/dependency&gt; 
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
              &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.data.version}&lt;/version&gt;
  
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-instrument&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.instrument.version}&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;        
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
              &lt;artifactId&gt;derbyclient&lt;/artifactId&gt;
              &lt;version&gt;10.11.1.1&lt;/version&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                      &lt;compilerArguments&gt;
                          &lt;endorseddirs&gt;${endorsed.dir}&lt;/endorseddirs&gt;
                      &lt;/compilerArguments&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.6&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;phase&gt;validate&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;copy&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;outputDirectory&gt;${external.resources}&lt;/outputDirectory&gt;
                              &lt;silent&gt;true&lt;/silent&gt;
                              &lt;artifactItems&gt;
                                  &lt;artifactItem&gt;
                                      &lt;groupId&gt;javax&lt;/groupId&gt;
                                      &lt;artifactId&gt;javaee-endorsed-api&lt;/artifactId&gt;
                                      &lt;version&gt;7.0&lt;/version&gt;
                                      &lt;type&gt;jar&lt;/type&gt;
                                  &lt;/artifactItem&gt;
                              &lt;/artifactItems&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
      &lt;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;unknown-jars-temp-repo&lt;/id&gt;
              &lt;name&gt;A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.&lt;/name&gt;
              &lt;url&gt;file:${project.basedir}/lib&lt;/url&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>applicationContext.xml</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!-- was: &lt;?xml version="1.0" encoding="UTF-8"?&gt; --&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:p="http://www.springframework.org/schema/p"
         xmlns:aop="http://www.springframework.org/schema/aop"
         xmlns:tx="http://www.springframework.org/schema/tx"
         xmlns:jpa="http://www.springframework.org/schema/data/jpa"
         xmlns:context="http://www.springframework.org/schema/context"
  
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
         http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
         http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd"&gt;
  
      &lt;jpa:repositories base-package="com.canreef.calendar"/&gt;
      &lt;context:component-scan base-package="com.canreef.calendar"/&gt;
      &lt;!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) --&gt;
      &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"/&gt;
          &lt;property name="url" value="jdbc:derby://localhost:1527/GEAH"/&gt;
          &lt;property name="username" value="xxx"/&gt;
          &lt;property name="password" value="xxx"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
          &lt;property name="showSql" value="true" /&gt;
          &lt;property name="generateDdl" value="true" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
          &lt;property name="persistenceUnitName" value="Test_PU"/&gt;
          &lt;property name="jpaVendorAdapter" ref="jpaVendorAdapter"/&gt;
          &lt;property name="packagesToScan" value="com.canreef.calendar"/&gt;
  
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Really appreciate it if anybody can point out what is wrong in my code. </p>