SpringPersistenceUnitInfo :: AbstractMethodError

时间:2011-11-07 09:13:55

标签: spring jpa-2.0

我有一个使用Spring 3.0.5,JPA2和Hibernate 3.6.7的应用程序。 Maven正在处理我的依赖管理。这是一个pom摘录:

<properties>
  <spring.version>3.0.5.RELEASE</spring.version>
</properties>
<dependencies>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring.version}</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
  </dependency>
...
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-hibernate3</artifactId>
    <version>2.0.8</version>
    <scope>compile</scope>
      <exclusions>
         <exclusion>
       <groupId>org.hibernate</groupId>
       <artifactId>hibernate</artifactId>
     </exclusion>
      </exclusions>
  </dependency>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>3.6.7.Final</version>
  </dependency>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>3.6.7.Final</version>
    <scope>compile</scope>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jpa</artifactId>
    <version>2.0.8</version>
    <scope>compile</scope>
  </dependency>
  <dependency>
    <groupId>org.hibernate.java-persistence</groupId>
    <artifactId>jpa-api</artifactId>
    <version>2.0-cr-1</version>
    <scope>compile</scope>
  </dependency>
...

应用程序构建得很好,但是,当尝试加载它时,Tomcat容器会抱怨以下内容:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

有关可能导致此问题的任何想法?所有依赖关系似乎都完好无损。

感谢。

3 个答案:

答案 0 :(得分:6)

您正在混合Spring 2.x和3.x中的工件。

将旧版spring-hibernate3spring-jpa替换为

<dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-orm</artifactId>
     <version>${spring.version}</version>
     <scope>compile</scope>
</dependency> 

答案 1 :(得分:0)

我有完全相同的问题。我是hibernate验证器(4.2),tomcat 6和spring 3.0.6。但我也将hibernate从3.2升级到3.6,但我忘了从类路径中删除hibernate-entitymanager.jar(这是一个旧的hibernate jar)。

答案 2 :(得分:0)

我遇到了与Hibernate 4.x,Spring 3.x,JPA 2.x和CXF 2.7.5非常类似的问题。我在maven POM文件中删除了对spring-jpa工件的引用,并插入了推荐的代码片段。工作魔法!我不再看到例外。谢谢!