Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-1020

eager fetching of PersistentCollection of a primitive type fails

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.1, 2.0.0-M2
    • Fix Version/s: 2.0.0-beta
    • Component/s: jdbc
    • Labels:
      None
    • Environment:

      Description

      When a PersistentCollection of primitives like String.class are persisted, if the collection is marked as eager fetching. An exception is thrown upon loading the collection :

      Attached is a patch file to the 2.0.0 trunk's junit test which illustrates the collection working with lazy and failing with eager. This also happens in 1.2.1

      Exception below:
      --------------------

      junit.framework.AssertionFailedError: java.lang.String cannot be cast to org.apache.openjpa.enhance.PersistenceCapable
      at junit.framework.Assert.fail(Assert.java:47)
      at org.apache.openjpa.persistence.annotations.TestPersistentCollection.testPersistentCollectionStringsEager(TestPersistentCollection.java:169)
      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:597)
      at junit.framework.TestCase.runTest(TestCase.java:154)
      at junit.framework.TestCase.runBare(TestCase.java:127)
      at org.apache.openjpa.persistence.test.PersistenceTestCase.runBare(PersistenceTestCase.java:455)
      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 org.apache.openjpa.persistence.test.PersistenceTestCase.run(PersistenceTestCase.java:182)
      at junit.framework.TestSuite.runTest(TestSuite.java:208)
      at junit.framework.TestSuite.run(TestSuite.java:203)
      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:597)
      at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
      at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
      at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
      at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
      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:597)
      at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:334)
      at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:980)

      1. openjpa_junit_patch.zip
        1 kB
        Ted Leung
      2. openjpa_jdbc_patch.zip
        0.6 kB
        Ted Leung

        Activity

        Hide
        tedman@sfu.ca Ted Leung added a comment -

        a patch to the junit tests illustrating the problem

        Show
        tedman@sfu.ca Ted Leung added a comment - a patch to the junit tests illustrating the problem
        Hide
        tedman@sfu.ca Ted Leung added a comment -

        a fix for the problem, it was my best guess and I'm not that familiar with the code so please read it over to make sure it makes sense.

        Show
        tedman@sfu.ca Ted Leung added a comment - a fix for the problem, it was my best guess and I'm not that familiar with the code so please read it over to make sure it makes sense.
        Hide
        tedman@sfu.ca Ted Leung added a comment -

        It appears that in the JDBC Store Manager it assumes that the item in the collections is an entity or a persist capable object. In the case of PersistentCollections, I don't think that's true as you can store Strings,Enums etc... so I added a check in the loop to make sure it's a persist capable object before trying to cast and assign a reverse mapping.

        It's entirely possible that the setInverseRelation() should never have been called at all for that collection... but I'm not sure. The patch I submitted just checked each element in the collection at the time of setting the inverse.

        Show
        tedman@sfu.ca Ted Leung added a comment - It appears that in the JDBC Store Manager it assumes that the item in the collections is an entity or a persist capable object. In the case of PersistentCollections, I don't think that's true as you can store Strings,Enums etc... so I added a check in the loop to make sure it's a persist capable object before trying to cast and assign a reverse mapping. It's entirely possible that the setInverseRelation() should never have been called at all for that collection... but I'm not sure. The patch I submitted just checked each element in the collection at the time of setting the inverse.
        Hide
        dleangen David Leangen added a comment -

        This patch seems to work ok for me, too.

        Show
        dleangen David Leangen added a comment - This patch seems to work ok for me, too.
        Hide
        faywang Fay Wang added a comment -

        The fix and the test case have been checked into trunk level code. It is not ported to openjpa 1.2 yet.

        Show
        faywang Fay Wang added a comment - The fix and the test case have been checked into trunk level code. It is not ported to openjpa 1.2 yet.
        Hide
        kwsutter Kevin Sutter added a comment -

        Marking the fix versions since this was integrated back on 01/04/2010.

        Show
        kwsutter Kevin Sutter added a comment - Marking the fix versions since this was integrated back on 01/04/2010.

          People

          • Assignee:
            mcconne Tim McConnell
            Reporter:
            tedman@sfu.ca Ted Leung
          • Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development