Announcement Announcement Module
Collapse
No announcement yet.
AbstractMethodError when deploying Spring + Hibernate + JPA2 as a WAR Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AbstractMethodError when deploying Spring + Hibernate + JPA2 as a WAR

    Hi,

    we have a web application that uses Spring 3, Hibernate 3.5 and and JPA2 and is managed using Maven. When running it through Maven (for example mvn jetty:run), it works perfectly. But strangely, when packaged as a WAR it fails to start.

    I created a minimal web application to demonstrate the problem. It actually contains no executable code, it just configures a memory database, Hibernate, JPA and Spring's Dispatcher servlet. When started within maven as mvn jetty:run, and also mvn tomcat:run, it starts as expected. However, when packaged as a WAR and deployed, it fails to start with this exception:
    Code:
    Caused by: java.lang.AbstractMethodError: org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;
    	at org.hibernate.ejb.util.LogHelper.logPersistenceUnitInfo(LogHelper.java:39)
    	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:509)
    	at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72)
    	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:218)
    	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:251)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
    	... 42 more
    The problem can be also demonstrated by running mvn tomcat:run-war.

    I'm attaching the demonstration application.

    Any idea what is causing the problem and how to solve it? I've been looking for a solution for several hours already, but without success. Presumably it is somehow related to SPR-6408 Add full support for JPA 2.0 PersistenceUnitInfo and SPR-6705 Spring 3.0 not compatible with Hibernate 3.5 beta3. In class org.springframework.orm.jpa.persistenceunit.Defaul tPersistenceUnitManager a presence of JPA2 is checked and if present, the instance of PersistenceUnitInfo is wrapped into a proxy that adds JPA2 specific method. But it looks like the solution is not perfect and in my case it fails.

    Thanks for help,
    Petr

    ------------------------------------------------------------------

    PS: I'm attaching the important sources for convenience:

    pom.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>org.example</groupId>
      <artifactId>jpa2</artifactId>
      <packaging>war</packaging>
      <name>JPA2 + Spring problem example</name>
      <version>1.0-SNAPSHOT</version>
    
      <properties>
        <hibernate.version>3.5.1-Final</hibernate.version>
        <spring.version>3.0.5.RELEASE</spring.version>
        <logback.version>0.9.27</logback.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
    
      <!-- ================================================ -->
      <!-- DEPENDENCIES                                     -->
      <!-- ================================================ -->
      <dependencies>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
          <version>${spring.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
          <version>${spring.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-beans</artifactId>
          <version>${spring.version}</version>
        </dependency>
    
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-orm</artifactId>
          <version>${spring.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-jpa</artifactId>
          <version>2.0.8</version>
        </dependency>
    
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
          <version>${spring.version}</version>
        </dependency>
    
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
          <version>${hibernate.version}</version>
          <exclusions>
    	<exclusion>
    	  <groupId>org.slf4j</groupId>
    	  <artifactId>slf4j-api</artifactId>
    	</exclusion>
          </exclusions>
        </dependency>
    
        <!-- Logging -->
        <dependency>
          <groupId>ch.qos.logback</groupId>
          <artifactId>logback-classic</artifactId>
          <version>${logback.version}</version>
        </dependency>
    
        <!-- Embedded database -->
        <dependency>
          <groupId>org.hsqldb</groupId>
          <artifactId>hsqldb</artifactId>
          <version>2.0.0</version>
        </dependency>
      </dependencies>
    
    
      <!-- ================================================ -->
      <!-- BUILD                                            -->
      <!-- ================================================ -->
      <build>
        <plugins>
          <!-- JETTY -->
          <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>6.1.26</version>
            <dependencies>
              <dependency>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-plus</artifactId>
                <version>6.1.16</version>
              </dependency>
            </dependencies>
            <configuration>
              <contextPath>/</contextPath>
            </configuration>
          </plugin>
    
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>tomcat-maven-plugin</artifactId>
            <version>1.1</version>
            <dependencies>
            </dependencies>
          </plugin>
        </plugins>
      </build>
    
      <!-- ================================================ -->
      <!--            Repository Configuration              -->
      <!-- ================================================ -->
    
      <repositories>
        <repository>
          <id>spring-ext</id>
          <name>Spring External Dependencies Repository</name>
          <url>
    	https://springframework.svn.sourceforge.net/svnroot/springframework/repos/repo-ext/
          </url>
        </repository>
        <!-- pro Hibernate: -->
        <repository>
          <id>jboss</id>
          <name>JBoss Maven2 Repository</name>
          <url>http://repository.jboss.org/maven2/</url>
        </repository>
      </repositories>
    </project>
    Spring configuration (context-main.xml):
    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      ">
    
      <bean id="dataSource" class="org.hsqldb.jdbc.JDBCDataSource">
        <property name="database" value="jdbc:hsqldb:mem:playground" />
        <property name="user" value="sa" />
        <property name="password" value="" />
      </bean>
    
      <bean name="persistenceUnitManager"
        class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
        <property name="defaultDataSource" ref="dataSource" />
      </bean>
    
      <bean name="hibernateJpaVendorAdapter"
        class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="generateDdl" value="true" />
      </bean>
    
      <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="default" />
        <property name="persistenceUnitManager" ref="persistenceUnitManager"/>
        <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
      </bean>
    </beans>
    Last edited by petrp; Apr 22nd, 2011, 05:37 AM. Reason: adding sources into the post for convenience

  • #2
    You are mixing spring version NEVER do that... Remove spring-jpa from your pom.

    Comment


    • #3
      solved

      Originally posted by Marten Deinum View Post
      You are mixing spring version NEVER do that... Remove spring-jpa from your pom.
      Thanks a lot. Such a stupid mistake. For some reason I thought that spring-jpa is versioned separately from the Spring framework and so I didn't find it odd that it's version is different. Removing it solved the problem.

      Comment


      • #4
        another AbstractMethodError

        I am also getting this kind of error, but from Spring Data JPA 1.0.0.M2:
        Caused by: java.lang.AbstractMethodError: org.springframework.data.repository.support.Reposi toryFactorySupport.getRepositoryBaseClass(Lorg/springframework/data/repository/support/RepositoryMetadataLjava/lang/Class;
        at org.springframework.data.repository.support.Reposi toryFactorySupport.getRepositoryInformation(Reposi toryFactorySupport.java:167)
        at org.springframework.data.repository.support.Reposi toryFactorySupport.getRepository(RepositoryFactory Support.java:128)
        at org.springframework.data.repository.support.Reposi toryFactoryBeanSupport.getObject(RepositoryFactory BeanSupport.java:107)
        at org.springframework.data.repository.support.Reposi toryFactoryBeanSupport.getObject(RepositoryFactory BeanSupport.java:36)
        at org.springframework.beans.factory.support.FactoryB eanRegistrySupport.doGetObjectFromFactoryBean(Fact oryBeanRegistrySupport.java:142)
        ... 40 more

        I'm using hibernate 3.6.3.Final, using Maven. Have fixed a lot of version problems, this is the last problem we have to fix -- hopefully!

        Comment


        • #5
          Spring Data JPA M2 requires Spring Data Commons Core M5 (as stated in the pom.xml). Make sure you have that in the classpath.
          Last edited by Oliver Gierke; May 6th, 2011, 08:51 AM.

          Comment


          • #6
            Oliber, (thanks for the quick reply by the way!) do you mean JPA M2?
            Yes I changed to use Spring Data Commons Core M5 with Spring Data JPA M2, but now get another AbstractMethod error, if you can have a look:

            Caused by: java.lang.AbstractMethodError: org.hibernate.ejb.EntityManagerFactoryImpl.getMeta model()Ljavax/persistence/metamodel/Metamodel;
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.springframework.orm.jpa.AbstractEntityManagerF actoryBean.invokeProxyMethod(AbstractEntityManager FactoryBean.java:423)
            at org.springframework.orm.jpa.AbstractEntityManagerF actoryBean$ManagedEntityManagerFactoryInvocationHa ndler.invoke(AbstractEntityManagerFactoryBean.java :485)
            at $Proxy24.getMetamodel(Unknown Source)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.springframework.orm.jpa.SharedEntityManagerCre ator$SharedEntityManagerInvocationHandler.invoke(S haredEntityManagerCreator.java:176)
            at $Proxy28.getMetamodel(Unknown Source)
            at org.springframework.data.jpa.repository.utils.JpaC lassUtils.getMetadata(JpaClassUtils.java:97)
            at org.springframework.data.jpa.repository.support.Jp aRepositoryFactory.getEntityInformation(JpaReposit oryFactory.java:162)
            at org.springframework.data.jpa.repository.support.Jp aRepositoryFactory.getTargetRepository(JpaReposito ryFactory.java:91)
            at org.springframework.data.jpa.repository.support.Jp aRepositoryFactory.getTargetRepository(JpaReposito ryFactory.java:72)
            at org.springframework.data.repository.support.Reposi toryFactorySupport.getRepository(RepositoryFactory Support.java:132)
            at org.springframework.data.repository.support.Reposi toryFactoryBeanSupport.getObject(RepositoryFactory BeanSupport.java:107)
            at org.springframework.data.repository.support.Reposi toryFactoryBeanSupport.getObject(RepositoryFactory BeanSupport.java:36)
            at org.springframework.beans.factory.support.FactoryB eanRegistrySupport.doGetObjectFromFactoryBean(Fact oryBeanRegistrySupport.java:142)

            Comment


            • #7
              I just fixed the type, I wanted to refer to Spring Data JPA M2 just as you said. Apparently you're not using a JPA 2 capable version of Hibernate. Make sure you have Hibernate 3.5 or higher.

              Comment


              • #8
                Now it's working! here is where I got stuck:
                I loaded hibernate core 3.6., but left the entity manager to use 3.3.
                thanks a lot!

                Comment

                Working...
                X