我正在使用 Spring-Data-JPA 1.0.3.RELEASE 来管理我的 ORM。
我的 persistence.xml 看起来像这样:
<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 看起来像这样
<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 界面如下所示:
@Transactional(readOnly = true)
public interface OrderRepository extends JpaRepository<Order, Long> {
//my stuff
}
我在我的服务类中使用它
@Autowired
private OrderRepository repository;
但看起来 websphere 不太喜欢它,并给了我这个错误:
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 的错误 - 但是:我把它留给 maven 所以data-commons 版本应该没问题。我还发现 Spring Data JPA 需要 JPA 2.0 实现,所以我检查了 websphere 服务器上的 openJPA 版本,这很好。
有什么想法可能导致这种情况吗?