使用注入的Spring Data JPA返回"NoSuchMethodError". [英] Spring Data JPA using injection returns "NoSuchMethodError"

查看:205
本文介绍了使用注入的Spring Data JPA返回"NoSuchMethodError".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring-Data-JPA 1.0.3.RELEASE来管理我的ORM.

I'm using Spring-Data-JPA 1.0.3.RELEASE to manage my ORM.

我的persistence.xml看起来像这样:

my persistence.xml looks like this:

<persistence>
    <persistence-unit name="default" transaction-type="JTA">
        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <jta-data-source>jdbc/myDataSource</jta-data-source>
        <properties>
            <property name="openjpa.TransactionMode" value="managed" />
            <property name="openjpa.ConnectionFactoryMode" value="managed" />
            <property name="openjpa.jdbc.DBDictionary" value="db2" />
        </properties>
    </persistence-unit>
</persistence>

applicationContext看起来像这样

applicationContext looks like this

<beans>
<context:annotation-config />
<bean id="myExceptionTranslator" class="org.springframework.orm.jpa.DefaultJpaDialect" />

<bean id="myEmf" class="javax.persistence.Persistence" factory-method="createEntityManagerFactory">
        <constructor-arg type="java.lang.String" value="default" />
</bean>
    <jpa:repositories base-package="model.repositories" />
    <tx:annotation-driven transaction-manager="txManager" />
    <bean
        class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
</beans>

我的OrderRepo界面如下:

my OrderRepo interface looks like this:

@Transactional(readOnly = true)
public interface OrderRepository extends JpaRepository<Order, Long> {
//my stuff
}

我正在服务类中这样使用它

and i'm using it like this within my service class

@Autowired
private OrderRepository repository;

但是看起来websphere不太喜欢它,并给了我这个错误:

But it looks like websphere dosn't like it as much and gives me this error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private model.repositories.OrderRepository model.service.OrderService.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderRepository': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: javax/persistence/EntityManager.getMetamodel()Ljavax/persistence/metamodel/Metamodel;

我发现的有关此问题的唯一资源指出了以前的Spring-Data-JPA版本中的错误,这些错误现在被标记为已修复,或者使用了对spring-data-commons jar的错误依赖项而导致的错误-但是:我要离开要行事,所以数据通用版本应该没问题.我还发现spring数据JPA需要JPA 2.0实现,因此我在websphere服务器上检查了openJPA版本,这很好.

the only ressource i found regarding this problem points out errors in previous Spring-Data-JPA versions which are marked as fixed by now or errors using wrong dependencies to the spring-data-commons jar - however: i'm leaving that to maven so the data-commons version should be fine. also i found that spring data JPA needs a JPA 2.0 implementation so i checked for the openJPA version on the websphere server and it's fine.

有什么想法会导致这种情况吗?

Any ideas what could be causing this?

推荐答案

错误通知,javax.persistence.EntityManager中没有方法getMetaModel().

As the error informs, there is no method getMetaModel() in javax.persistence.EntityManager.

检查JPA 1.0和JPA 2.0的来源.

Check sources of JPA 1.0 and JPA 2.0.

EntityManager JPA 2.0

EntityManager JPA 1.0

此方法仅在2.0版中存在.我认为您应该仔细检查您的依赖项,如果在1.0版中没有JPA的罐子

This method exists only in version 2.0. In my opinion you should double check your dependencies if there is no jar of JPA in version 1.0

这篇关于使用注入的Spring Data JPA返回"NoSuchMethodError".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆