Hibernate 4 upgrade (java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode())

11,931

Solution 1

You're runtime is Java EE 5 (or older) while the code is expecteding Java EE 6. Looking at Java EE 5's PersistenceUnitInfo there's no such method getValidationModel(). You might be able to fix this simply by upgrading runtime to Java EE 6

Solution 2

I was using an 1.0.0 version of javax persistence lib

<dependency>
 <groupId>javax.persistence</groupId>
<artifactId>com.springsource.javax.persistence</artifactId>
<version>2.0.0</version>
 </dependency>

Changing the version fixed it.,

Share:
11,931
aanchal jain
Author by

aanchal jain

Updated on June 04, 2022

Comments

  • aanchal jain
    aanchal jain almost 2 years

    I am trying to upgrade my application from hibernate 3.4 to 4.1.0 FINAL version and getting the below mentioned error.

    I am using spring 3.2 right now. and my pom file looks like the following.

    <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>com.springsource.org.hibernate</artifactId>
            <version>4.1.0.Final</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- Hibernate JPA Provider -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>com.springsource.org.hibernate.ejb</artifactId>
            <version>4.1.0.Final</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>com.springsource.org.apache.commons.logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    

    Following is the entity manager and session factory

        <bean id="testSessionFactory"
            class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
            autowire="byName">
            <property name="dataSource" ref="testDataSource" />
            <property name="annotatedClasses">
                <list>
                    <value>test</value>
                </list>
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                    <prop key="hibernate.show_sql">false</prop>
                    <prop key="hibernate.hbm2ddl.auto">validate</prop>
                </props>
            </property>
        </bean>
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>
    <bean id="entityManagerFactory"
            class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="persistenceUnitName" value="unit" />
            <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="generateDdl" value="false" />
                    <property name="showSql" value="true" />
                </bean>
            </property>
            <property name="dataSource">
                <ref bean="datasource" />
            </property>
            <property name="jpaProperties">
                <props>
                    <prop key="hibernate.generate_statistics">false</prop>
                    <prop key="hibernate.cache.use_second_level_cache">false</prop>
                    <prop key="hibernate.cache.use_query_cache">false</prop>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                    <prop key="hibernate.show_sql">"true"</prop>
                </props>
            </property>
        </bean>
    

    Following is the error.

    [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)
    

    I followed the following link to upgrade the application. Help is appreciated.