3 Replies Latest reply on Jun 7, 2013 9:28 AM by emlun

    Getting "java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence" even though class is there

    D. Alvarado Newbie

      Hi,

       

      I'm using Maven 3.0.3 to try and deploy a Spring 3.1.1.RELEASE WAR to JBoss 7.1.1.Final.  I have configured my database access in my Spring application context like so …

       

      [code]

      <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

              <property name="packagesToScan" value="org.mainco.myco" />

              <property name="jpaVendorAdapter">

                  <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>

              </property>

              <property name="dataSource" ref="dataSource"/>

              <property name="jpaPropertyMap" ref="jpaPropertyMap" />

          </bean>

       

      <util:map id="jpaPropertyMap">

        <entry key="show_sql" value="true" />

        <entry key="dialect" value="org.hibernate.dialect.MySQLDialect" />

        <entry key="hibernate.hbm2ddl.auto" value="validate" />

          <entry key="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/>

          <entry key="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>

          <entry key="hibernate.cache.use_second_level_cache" value="true" />

          <entry key="hibernate.cache.use_query_cache" value="false" />

          <entry key="hibernate.generate_statistics" value="false" />

      </util:map>

       

      <bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">

        <property name="entityManagerFactory" ref="entityManagerFactory" />

      </bean>

       

      <!-- Application properties -->

      <bean id="propertyConfigurer"

        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

        <property name="locations">

        <list>

                                              <value>classpath:application.properties</value>

        </list>

        </property>

        <property name="ignoreUnresolvablePlaceholders" value="true" />

      </bean>

       

      <jee:jndi-lookup jndi-name="java:jboss/datasources/MySqlDS" id="dataSource" expected-type="javax.sql.DataSource"/>

       

      <tx:jta-transaction-manager />

      [/code]

       

      Since JBoss already comes with Hibernate, I'm not adding it to my WAR.  Bad sadly, I'm getting the below exception when I try and deploy ...

       

      [code]

      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#e604' defined in class path resource [META-INF/spring/infrastructure.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

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

                at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

                ... 46 more

      Caused by: 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

                at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

                at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:76) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

                ... 50 more

      Caused by: java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence

                at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.<init>(HibernateJpaVendorAdapter.java:57) [spring-orm-3.1.1.RELEASE.jar:3.1.1.RELEASE]

                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [classes.jar:1.6.0_37]

                at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [classes.jar:1.6.0_37]

                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [classes.jar:1.6.0_37]

                at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [classes.jar:1.6.0_37]

                at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

                ... 52 more

      Caused by: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence from [Module "deployment.myclient.war:main" from Service Module Loader]

                at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)

                at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)

                at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)

                at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)

                at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)

                at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)

      [/code]

       

      The class in question is here

       

      $JBOSS_HOME/modules/org/hibernate/main/hibernate-entitymanager-4.0.1.Final.jar

       

      Why doesn't Jboss find it and what else do I need to do to get this thing to deploy properly?  Thanks, - Dave