title: Hibernate 4 upgrade (java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode())
body: <p>I am trying to upgrade my application from hibernate 3.4 to 4.1.0 FINAL version and getting the below mentioned error. </p>
  
  <p>I am using spring 3.2 right now. and my pom file looks like the following. </p>
  
  <pre><code>&lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;com.springsource.org.hibernate&lt;/artifactId&gt;
          &lt;version&gt;4.1.0.Final&lt;/version&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;commons-logging&lt;/groupId&gt;
                  &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;!-- Hibernate JPA Provider --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;com.springsource.org.hibernate.ejb&lt;/artifactId&gt;
          &lt;version&gt;4.1.0.Final&lt;/version&gt;
          &lt;exclusions&gt;
              &lt;!-- Exclude Commons Logging in favor of SLF4j --&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
                  &lt;artifactId&gt;com.springsource.org.apache.commons.logging&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>Following is the entity manager and session factory </p>
  
  <pre><code>    &lt;bean id="testSessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
          autowire="byName"&gt;
          &lt;property name="dataSource" ref="testDataSource" /&gt;
          &lt;property name="annotatedClasses"&gt;
              &lt;list&gt;
                  &lt;value&gt;test&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;validate&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&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;bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="persistenceUnitName" value="unit" /&gt;
          &lt;property name="jpaVendorAdapter"&gt;
              &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                  &lt;property name="generateDdl" value="false" /&gt;
                  &lt;property name="showSql" value="true" /&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
          &lt;property name="dataSource"&gt;
              &lt;ref bean="datasource" /&gt;
          &lt;/property&gt;
          &lt;property name="jpaProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.generate_statistics"&gt;false&lt;/prop&gt;
                  &lt;prop key="hibernate.cache.use_second_level_cache"&gt;false&lt;/prop&gt;
                  &lt;prop key="hibernate.cache.use_query_cache"&gt;false&lt;/prop&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;"true"&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>Following is the error. </p>
  
  <pre><code>[ERROR] [main] 12-09 15:05:55,168 [ContextLoader] - Context initialization failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [api-service.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
      at 
  
  Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
      at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:633)
      at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:288)
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
      at 
  [ERROR] [main] 12-09 15:05:55,169 [log] - Failed startup of context org.mortbay.jetty.webapp.WebAppContext@3a780024{/,file:/Users/Aanchal/avos/platform/src/avos-api/src/main/webapp/}
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [api-service.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
  
  Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
      at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:633)
      at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
  </code></pre>
  
  <p>I followed the following link to upgrade the application. Help is appreciated. </p>