JPA + eclipseLink2.0 failed

In my test project, Spring container can't create a bean that extends JpaRepository due to following error.

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'srSvcInfoMtrRepository': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: javax.persistence.EntityManager.getMetamodel()Ljavax/persistence/metamodel/Metamodel;

It might be the problem relevant to JPA version.

I specified certain persistenceProvider in eclipelink2.0(org.eclipse.persistence.jpa.PersistenceProvider) at persistence.xml.

do you have any idea about this problem?

Stacktrace

2012-05-14 09:11:08 ERROR Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@112da40] to prepare test instance *> [net.tjjang.learn.spring_jpa.test.SrSvcInfoMtrTest@b6d6ab] java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211) at org.springframework.test.context.junit4.SpringJUnit4C lassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbac ks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'srSvcInfoMtrRepository': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: javax.persistence.EntityManager.getMetamodel()Ljavax/persistence/metamodel/Metamodel; at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102) at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1441) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:305) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframewor k.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1) at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228) at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124) at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148) ... 24 more > Caused by: java.lang.NoSuchMethodError: javax.persistence.EntityManager.getMetamodel()Ljavax/persistence/metamodel/Metamodel;* at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getMetadata(JpaEntityInformationSupport.java:56) at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:145) at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.g etTargetRepository(JpaRepositoryFactory.java:83) at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:66) at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:146) at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:120) at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:39) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)

JpaRepository Class()

package net.tjjang.learn.spring_jpa.repositories;
import net.tjjang.learn.spring_jpa.domain.SrSvcInfoMtr;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;

@Transactional(readOnly = true)
public interface SrSvcInfoMtrRepository extends JpaRepository<SrSvcInfoMtr, String> {
    Page<SrSvcInfoMtr> findBySvc_nm(String svc_nm, Pageable pageable);
}

app-context.xml(not all the contents of app-context.xml)

    <!-- for data access -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
    p:driverClassName="cubrid.jdbc.driver.CUBRIDDriver" p:url="jdbc:cubrid:localhost:30000:test:test::" 
    p:username="test" p:password="*******" p:initialSize="5" p:maxActive="10"> 
    </bean -->
<bean
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    id="entityManagerFactory">
    <property name="dataSource" ref="dataSource" />
    <property name="loadTimeWeaver">
        <bean
            class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
    </property>
    <property name="persistenceUnitName" value="JpaPersistenceUnit" />
</bean>

<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<jpa:repositories base-package="net.tjjang.learn.spring_jpa" />
<import resource="infrastructure.xml" />

Persistence.xml

    <persistence-unit name="JpaPersistenceUnit"
    transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>net.tjjang.learn.spring_jpa.domain.Car</class>
    <class>net.tjjang.learn.spring_jpa.domain.SrSvcInfoMtr</class>
    <properties>
        <property name="eclipselink.logging.level" value="INFO" />
    </properties>
</persistence-unit>

Libraries

  • orgspringframeworkspring-aop3.1.0.RELEASEspring-aop-3.1.0.RELEASE.jar

  • aopallianceaopalliance1.0aopalliance-1.0.jar

  • orgspringframeworkspring-asm3.1.0.RELEASEspring-asm-3.1.0.RELEASE.jar

  • orgspringframeworkspring-core3.1.0.RELEASEspring-core-3.1.0.RELEASE.jar

  • commons-loggingcommons-logging1.1.1commons-logging-1.1.1.jar

  • orgspringframeworkspring-orm3.1.0.RELEASEspring-orm-3.1.0.RELEASE.jar

  • orgspringframeworkspring-jdbc3.1.0.RELEASEspring-jdbc-3.1.0.RELEASE.jar

  • orgspringframeworkspring-tx3.1.0.RELEASEspring-tx-3.1.0.RELEASE.jar

  • orgspringframeworkspring-aspects3.1.0.RELEASEspring-aspects-3.1.0.RELEASE.jar

  • orgspringframeworkspring-context3.1.0.RELEASEspring-context-3.1.0.RELEASE.jar

  • orgspringframeworkspring-expression3.1.0.RELEASEspring-expression-3.1.0.RELEASE.jar

  • orgspringframeworkspring-context-support3.1.0.RELEASEspring-context-support-3.1.0.RELEASE.jar

  • orgspringframeworkspring-beans3.1.0.RELEASEspring-beans-3.1.0.RELEASE.jar

  • orgspringframeworkspring-test3.1.0.RELEASEspring-test-3.1.0.RELEASE.jar

  • orgspringframeworkspring-instrument3.1.0.RELEASEspring-instrument-3.1.0.RELEASE.jar

  • junitjunit4.8.2junit-4.8.2.jar

  • orgslf4jslf4j-api1.6.0slf4j-api-1.6.0.jar

  • orgslf4jjcl-over-slf4j1.6.0jcl-over-slf4j-1.6.0.jar

  • orgslf4jslf4j-log4j121.6.0slf4j-log4j12-1.6.0.jar

  • log4jlog4j1.2.16log4j-1.2.16.jar

  • cubridcubrid-jdbc8.4.1.2032cubrid-jdbc-8.4.1.2032.jar

  • orgeclipsepersistenceeclipselink2.0.0eclipselink-2.0.0.jar

  • orgspringframeworkdataspring-data-jpa1.0.3.RELEASEspring-data-jpa-1.0.3.RELEASE.jar

  • orgspringframeworkdataspring-data-commons-core1.1.0.RELEASEspring-data-commons-core-1.1.0.RELEASE.jar

  • orghibernateejb3-persistence1.0.2.GAejb3-persistence-1.0.2.GA.jar

  • orgaspectjaspectjrt1.6.8aspectjrt-1.6.8.jar
  • orgaspectjaspectjweaver1.6.11aspectjweaver-1.6.11.jar
  • commons-dbcpcommons-dbcp1.2.2-p1commons-dbcp-1.2.2-p1.jar
  • commons-poolcommons-pool1.4commons-pool-1.4.jar
  • mysqlmysql-connector-java5.1.10mysql-connector-java-5.1.10.jar

  • Spring Data JPA requires JPA 2.0. You have pulled the 1.0 version of it into your classpath (the ejb3-persistence-1.0.2.GA.jar , by whatever means). Make sure you use a recent version of EclipseLink that supports JPA 2.0. Version 2.3.2 is the current release version.

    链接地址: http://www.djcxy.com/p/60294.html

    上一篇: detachCopy使用ObjectDB处理JDO?

    下一篇: JPA + eclipseLink2.0失败