Announcement Announcement Module
Collapse
No announcement yet.
spring-data-jpa-example does not work with OpenJPA Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring-data-jpa-example does not work with OpenJPA

    Hi Spring Data Developers:

    Anyone out there has a workable Spring Data example with OpenJPA? The spring-data-jpa-example from SpringSource works with Hibernate but I cannot make it work with OpenJPA. Thanks for help.

    The error msg is attached here:


    -------------------------------------------------------
    T E S T S
    -------------------------------------------------------
    Running org.springframework.data.jpa.example.repository.Si mpleUserRepositorySample
    19:40:49,751 DEBUG ry.config.AbstractRepositoryConfigDefinitionParser : 110 - Triggering auto repository detection
    19:40:49,837 DEBUG ConfigDefinitionParser$RepositoryComponentProvider : 243 - Identified candidate component class: file [/Users/Li/Documents/workspace/spring-data-jpa/spring-data-jpa-example/target/classes/org/springframework/data/jpa/example/repository/simple/SimpleUserRepository.class]
    19:40:49,847 DEBUG ry.config.AbstractRepositoryConfigDefinitionParser : 233 - Registering repository: simpleUserRepository - Interface: org.springframework.data.jpa.example.repository.si mple.SimpleUserRepository - Factory: org.springframework.data.jpa.repository.support.Jp aRepositoryFactoryBean, - Custom implementation: null
    log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
    log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
    log4j:ERROR [org.springframework.instrument.classloading.Simple ThrowawayClassLoader@3f56e5ed] whereas object of type
    log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [sun.misc.Launcher$AppClassLoader@37b90b39].
    log4j:ERROR Could not instantiate appender named "stdout".
    log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
    log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
    log4j:ERROR [org.springframework.instrument.classloading.Simple InstrumentableClassLoader@158105e8] whereas object of type
    log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [sun.misc.Launcher$AppClassLoader@37b90b39].
    log4j:ERROR Could not instantiate appender named "stdout".
    19:40:51,557 DEBUG framework.data.jpa.repository.query.SimpleJpaQuery : 121 - Looking up query for method findByFirstname
    1177 jpa.sample INFO [main] openjpa.Runtime - Starting OpenJPA 2.2.0
    19:40:51,902 ERROR rg.springframework.test.context.TestContextManager : 324 - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.Dependenc yInjectionTestExecutionListener@76539f0d] to prepare test instance [org.springframework.data.jpa.example.repository.Si mpleUserRepositorySample@6bef4b2b]
    java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.TestContext.getAp plicationContext(TestContext.java:157)
    at org.springframework.test.context.support.Dependenc yInjectionTestExecutionListener.injectDependencies (DependencyInjectionTestExecutionListener.java:109 )
    at org.springframework.test.context.support.Dependenc yInjectionTestExecutionListener.prepareTestInstanc e(DependencyInjectionTestExecutionListener.java:75 )
    at org.springframework.test.context.TestContextManage r.prepareTestInstance(TestContextManager.java:321)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.createTest(SpringJUnit4ClassRunner.j ava:211)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner$1.runReflectiveCall(SpringJUnit4Clas sRunner.java:288)
    at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.methodBlock(SpringJUnit4ClassRunner. java:290)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.runChild(SpringJUnit4ClassRunner.jav a:231)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner. java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRu nner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRu nner.java:184)
    at org.springframework.test.context.junit4.statements .RunBeforeTestClassCallbacks.evaluate(RunBeforeTes tClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements .RunAfterTestClassCallbacks.evaluate(RunAfterTestC lassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.ja va:236)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.run(SpringJUnit4ClassRunner.java:174 )
    at org.apache.maven.surefire.junit4.JUnit4TestSet.exe cute(JUnit4TestSet.java:62)
    at org.apache.maven.surefire.suite.AbstractDirectoryT estSuite.executeTestSet(AbstractDirectoryTestSuite .java:140)
    at org.apache.maven.surefire.suite.AbstractDirectoryT estSuite.execute(AbstractDirectoryTestSuite.java:1 27)
    at org.apache.maven.surefire.Surefire.run(Surefire.ja va:177)
    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.apache.maven.surefire.booter.SurefireBooter.ru nSuitesInProcess(SurefireBooter.java:345)
    at org.apache.maven.surefire.booter.SurefireBooter.ma in(SurefireBooter.java:1009)
    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'simpleUserRepository': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.data.jpa.example.auditing.Audi tableUser
    at org.springframework.beans.factory.support.FactoryB eanRegistrySupport.doGetObjectFromFactoryBean(Fact oryBeanRegistrySupport.java:149)
    at org.springframework.beans.factory.support.FactoryB eanRegistrySupport.getObjectFromFactoryBean(Factor yBeanRegistrySupport.java:102)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getObjectForBeanInstance(AbstractBeanF actory.java:1441)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:305 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:464)
    at org.springframework.test.context.support.AbstractG enericContextLoader.loadContext(AbstractGenericCon textLoader.java:103)
    at org.springframework.test.context.support.AbstractG enericContextLoader.loadContext(AbstractGenericCon textLoader.java:1)
    at org.springframework.test.context.support.Delegatin gSmartContextLoader.loadContext(DelegatingSmartCon textLoader.java:228)
    at org.springframework.test.context.TestContext.loadA pplicationContext(TestContext.java:124)
    at org.springframework.test.context.TestContext.getAp plicationContext(TestContext.java:148)
    ... 28 more
    Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.data.jpa.example.auditing.Audi tableUser
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at org.apache.openjpa.meta.MetaDataRepository.classFo rName(MetaDataRepository.java:1552)
    at org.apache.openjpa.meta.MetaDataRepository.loadPer sistentTypesInternal(MetaDataRepository.java:1528)
    at org.apache.openjpa.meta.MetaDataRepository.loadPer sistentTypes(MetaDataRepository.java:1506)
    at org.apache.openjpa.meta.MetaDataRepository.loadPer sistentTypes(MetaDataRepository.java:1486)
    at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.s ynchronizeMappings(JDBCBrokerFactory.java:141)
    at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.s ynchronizeMappings(JDBCBrokerFactory.java:164)
    at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.n ewBrokerImpl(JDBCBrokerFactory.java:122)
    at org.apache.openjpa.kernel.AbstractBrokerFactory.ne wBroker(AbstractBrokerFactory.java:209)
    at org.apache.openjpa.kernel.DelegatingBrokerFactory. newBroker(DelegatingBrokerFactory.java:156)
    at org.apache.openjpa.persistence.EntityManagerFactor yImpl.createEntityManager(EntityManagerFactoryImpl .java:227)

  • #2
    Judging from the stacktrace you have a classloading problem and/or are missing jars.

    Classpath
    Code:
    og4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
    log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 
    log4j:ERROR [org.springframework.instrument.classloading.Simple ThrowawayClassLoader@3f56e5ed] whereas object of type 
    log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [sun.misc.Launcher$AppClassLoader@37b90b39].
    Judging from this you have log4j in multiple classloaders, hibernate has its own logging and aparently OpenJPA uses log4j...

    No Class Found
    Code:
    Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.data.jpa.example.auditing.AuditableUser
    Please next time use [ code][/code ] tags when posting code/stacktrace/xml./

    Comment

    Working...
    X