Announcement Announcement Module
Collapse
No announcement yet.
Spring + TopLink + Embedded Derby Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring + TopLink + Embedded Derby

    I've been trying to get Mark Fisher's 'Getting Started with JPA in Spring 2.0' blog step by step guide to using JPA in a standalone environment working with Apache Derby. I can get the tests running using embedded HSQLDB and using a networked Derby Db, but I cannot get it working with an embedded Derby DB which is unfortunately my real need.

    I also get similar issues if I try and switch to Hibernate rather than TopLink. I converted the entities to just use plain Toplink + Embedded Derby without Spring and that also works. However, the combination of Spring + Toplink + Embedded Derby gives exceptions of the form shown below

    PHP Code:
    Local Exception Stack
    Exception [TOPLINK-4002] (Oracle TopLink Essentials 2006.8 (Build 060908)): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception
    SQL ExceptionCannot create an instance of generated class org.apache.derby.exe.ac6074401fx010fx34bbx3b99x000000142da011.Error Code20000
    Call
    :SELECT IDNAMEADDRESS_ID FROM RESTAURANT WHERE (ID = ?)
        
    bind => [1]
    Query:ReadObjectQuery(springjpa.Restaurant)
        
    at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:303)
        
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:551)
        
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:437)
        
    at oracle.toplink.essentials.internal.sessions.AbstractSession.executeCall(AbstractSession.java:675)
        
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:213)
        
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:199)
        
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.selectOneRow(DatasourceCallQueryMechanism.java:620)
        
    at oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.selectOneRowFromTable(ExpressionQueryMechanism.java:2152)
        
    at oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.selectOneRow(ExpressionQueryMechanism.java:2127)
        
    at oracle.toplink.essentials.queryframework.ReadObjectQuery.executeObjectLevelReadQuery(ReadObjectQuery.java:350)
        
    at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:709)
        
    at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:609)
        
    at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:677)
        
    at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:731)
        
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2218)
        
    at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:937)
        
    at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:894)
        
    at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.findInternal(EntityManagerImpl.java:298)
        
    at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.findInternal(EntityManagerImpl.java:274)
        
    at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.find(EntityManagerImpl.java:130)
        
    at org.springframework.orm.jpa.JpaTemplate$1.doInJpa(JpaTemplate.java:221)
        
    at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:183)
        
    at org.springframework.orm.jpa.JpaTemplate.find(JpaTemplate.java:219)
        
    at springjpa.JpaRestaurantDao.findById(JpaRestaurantDao.java:9)
        
    at springjpa.JpaRestaurantDaoTests.testFindByIdWhereRestaurantExists(JpaRestaurantDaoTests.java:42)
        
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        
    at java.lang.reflect.Method.invoke(Method.java:585)
        
    at junit.framework.TestCase.runTest(TestCase.java:154)
        
    at junit.framework.TestCase.runBare(TestCase.java:127)
        
    at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
        
    at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.access$001(AbstractAnnotationAwareTransactionalTests.java:44)
        
    at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests$1.run(AbstractAnnotationAwareTransactionalTests.java:112)
        
    at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runTest(AbstractAnnotationAwareTransactionalTests.java:177)
        
    at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runTestTimed(AbstractAnnotationAwareTransactionalTests.java:150)
        
    at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runBare(AbstractAnnotationAwareTransactionalTests.java:108)
        
    at org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:160)
        
    at org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:239)
        
    at junit.framework.TestResult$1.protect(TestResult.java:106)
        
    at junit.framework.TestResult.runProtected(TestResult.java:124)
        
    at junit.framework.TestResult.run(TestResult.java:109)
        
    at junit.framework.TestCase.run(TestCase.java:118)
        
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
        
    at junit.framework.TestSuite.run(TestSuite.java:203
    I've included here my persistence.xml and my applicationContext.xml.

    applicationContext.xml
    PHP Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">

      <bean id="restaurantDao" class="springjpa.JpaRestaurantDao">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
      </bean>

      <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="persistenceUnitName" value="SpringJpaGettingStarted"/>
        <property name="jpaVendorAdapter">
          <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
            <property name="showSql" value="true"/>
            <property name="generateDdl" value="true"/>
            <property name="databasePlatform" value="oracle.toplink.essentials.platform.database.DerbyPlatform"/>
          </bean>
        </property>
               <property name="loadTimeWeaver">
               <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
           </property>
        
      </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
        <property name="url" value="jdbc:derby:springjpa99;create=true"/>
        <property name="username" value="sa"/>
        <property name="password" value="foobar"/>
      </bean>
     
      <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
        <property name="dataSource" ref="dataSource"/>
      </bean>

    </beans>
    persistence.xml
    PHP Code:
    <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">

      <
    persistence-unit name="SpringJpaGettingStarted">
            <
    provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
            <class>
    springjpa.Restaurant</class>
            <class>
    springjpa.Address</class>
            <class>
    springjpa.Entree</class>
            
      </
    persistence-unit>

    </
    persistence
    Can anyone give any clues? From trawling the net looking for similar issues I'm wondering if this is today with load time weaving issues, but I'm not really sure what the load time weaving is doing. I tried adding in the InstrumentationLoadTimeWeaver and starting the tests by specifying both the spring-agent.jar and the toplink-essentials-agent.jar but neither approach made any difference.

    I was really hoping to use Spring to enable me to manage EntityManager and transactions declaratively but this looks like it could be a show-stopper if I can't figure it out - probably have to go back to hardcoding all the EntityManager transaction calls.

    Thanks for any insight
    Martin

  • #2
    Missing part of stack trace

    Looks like I cut of the bottom part of the stack trace so here it is in full:

    PHP Code:
    Local Exception Stack
    Exception [TOPLINK-4002] (Oracle TopLink Essentials 2006.8 (Build 060908)): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception
    SQL ExceptionCannot create an instance of generated class org.apache.derby.exe.ac6074401fx010fx34bbx3b99x000000142da011.Error Code20000
    Call
    :SELECT IDNAMEADDRESS_ID FROM RESTAURANT WHERE (ID = ?)
        
    bind => [1]
    Query:ReadObjectQuery(springjpa.Restaurant)
        
    at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:303)
        
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:551)
        
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:437)
        
    at oracle.toplink.essentials.internal.sessions.AbstractSession.executeCall(AbstractSession.java:675)
        
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:213)
        
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:199)
        
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.selectOneRow(DatasourceCallQueryMechanism.java:620)
        
    at oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.selectOneRowFromTable(ExpressionQueryMechanism.java:2152)
        
    at oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.selectOneRow(ExpressionQueryMechanism.java:2127)
        
    at oracle.toplink.essentials.queryframework.ReadObjectQuery.executeObjectLevelReadQuery(ReadObjectQuery.java:350)
        
    at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:709)
        
    at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:609)
        
    at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:677)
        
    at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:731)
        
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2218)
        
    at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:937)
        
    at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:894)
        
    at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.findInternal(EntityManagerImpl.java:298)
        
    at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.findInternal(EntityManagerImpl.java:274)
        
    at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.find(EntityManagerImpl.java:130)
        
    at org.springframework.orm.jpa.JpaTemplate$1.doInJpa(JpaTemplate.java:221)
        
    at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:183)
        
    at org.springframework.orm.jpa.JpaTemplate.find(JpaTemplate.java:219)
        
    at springjpa.JpaRestaurantDao.findById(JpaRestaurantDao.java:9)
        
    at springjpa.JpaRestaurantDaoTests.testFindByIdWhereRestaurantExists(JpaRestaurantDaoTests.java:42)
        
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        
    at java.lang.reflect.Method.invoke(Method.java:585)
        
    at junit.framework.TestCase.runTest(TestCase.java:154)
        
    at junit.framework.TestCase.runBare(TestCase.java:127)
        
    at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
        
    at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.access$001(AbstractAnnotationAwareTransactionalTests.java:44)
        
    at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests$1.run(AbstractAnnotationAwareTransactionalTests.java:112)
        
    at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runTest(AbstractAnnotationAwareTransactionalTests.java:177)
        
    at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runTestTimed(AbstractAnnotationAwareTransactionalTests.java:150)
        
    at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runBare(AbstractAnnotationAwareTransactionalTests.java:108)
        
    at org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:160)
        
    at org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:239)
        
    at junit.framework.TestResult$1.protect(TestResult.java:106)
        
    at junit.framework.TestResult.runProtected(TestResult.java:124)
        
    at junit.framework.TestResult.run(TestResult.java:109)
        
    at junit.framework.TestCase.run(TestCase.java:118)
        
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
        
    at junit.framework.TestSuite.run(TestSuite.java:203)
        
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
        
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused bySQL ExceptionCannot create an instance of generated class org.apache.derby.exe.ac6074401fx010fx34bbx3b99x000000142da011.
        
    at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
        
    at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
        
    at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
        
    at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
        
    at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
        
    at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
        
    at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
        
    at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
        
    at org.apache.derby.jdbc.Driver30.newEmbedPreparedStatement(Unknown Source)
        
    at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
        
    at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
        
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1147)
        
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:597)
        
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:470)
        ... 
    49 more 

    Comment


    • #3
      Curiouser and curiouser

      I decided to download the latest version of Derby to see if that made any difference. I was using 10.1.3.1. I upgraded to 10.2.1.6. However, this made no difference - still get same error.

      So then I downloaded the lib debug build of 10.2.1.6 to see if I could try and debug it to find out a bit more info on the problem. However, when I run against the debug builds of the derby libraries it all works fine!

      Does that give anyone who may be more intelligent than me any insight into why the standard builds do not work? What could possibly be different between the debug and standard builds that might affect how this works? (apart from the obvious - i.e. they are not the same code! - I'm assuming Derby have not screwed up there builds).

      Thanks
      Martin

      Comment


      • #4
        Martin, try first using another Toplink build (2006.8 seems a bit old). If you still experience the problem then please raise an issue on JIRA giving as much information as possible on the versions you are using.
        It would help tracking the bug if you could submit also a very small/simple test which triggers the errors which you are seeing.

        By the looks of your configuration, everything seems to be in order and since two other databases work, the embedded derby instance might be to blame (something to do with the jdbc driver maybe?).

        P.S. Sorry for the late reply, just spotted your post now.

        Comment


        • #5
          Hi Costin

          Thanks for the interest. I was able to move on from this issue by using the debug build of Derby. Then eventually I was able to get JPA+Spring+Toplink+Embedded Derby working in an Eclipse RCP app which was my ultimate goal (with the regular binary Derby build as well).

          Looking back at the original example that was causing problems, the main difference is that the example was using the Spring JpaDaoSupport and AbstractJpaTests classes. Now, I just have a plain Dao and have not tried writing Junit tests for it yet. So it's possible that these classes in combination with something in the Derby driver were causing issues. When I get chance I will try and wrap up the example in a demo and raise a JIRA bug.

          Thanks
          Martin

          Comment


          • #6
            AbstractJpaTests with Embedded Derby

            I'm trying to use AbstractJpaTests with an embedded Derby and I think I'm getting a very similar error. I'm using Hibernate, not Toplink for my JPA.

            Code:
            2007-01-25 18:33:23,054 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Cannot create an instance of generated class org.apache.derby.exe.ac07170079x0110x5c3fxce6cx0000001411100.
            2007-01-25 18:33:23,054 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Java exception: 'loader constraint violation: when resolving overridden method "org.apache.derby.exe.ac07170079x0110x5c3fxce6cx0000001411100.execute()Lorg/apache/derby/iapi/sql/ResultSet;" the class loader (instance of org/apache/derby/impl/services/reflect/ReflectLoaderJava2) of the current class, org/apache/derby/exe/ac07170079x0110x5c3fxce6cx0000001411100, and its superclass loader (instance of sun/misc/Launcher$AppClassLoader), have different Class objects for the type org/apache/derby/iapi/sql/ResultSet used in the signature: java.lang.LinkageError'.
            2007-01-25 18:33:23,064 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - could not complete schema update
            org.hibernate.exception.GenericJDBCException: could not get table metadata:
            I've tried various versions of derby including 10.2.2.0, 10.2.1.6, and the one from Java 6. Right now, I have no idea what is causing this.

            Comment


            • #7
              Guessing that it was a classloader issue, I noticed AbstractJpaTests reference a ShadowingClassLoader, so I tried turning it off and my tests now run.

              Code:
              @Override
              protected boolean shouldUseShadowLoader() {
                return false;
              }
              What is that ShadowingClassLoader supposed to do? I'll need to look into that later.

              cheers,
              Cameron

              Comment


              • #8
                I just wanted to let the community know that I was experiencing the same effect with Hibernate EntityManager 3.2.1.ga (but haven't tried with TopLink).
                It seems that this occurs only when using the Derby EmbeddedDriver, try ClientDriver and the symptoms are gone!

                Comment

                Working...
                X