OpenJPA
  1. OpenJPA
  2. OPENJPA-494

Single Table Inheritance Strategy causes errors when reading entities from the database (discriminator problem)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.0, 1.0.1, 1.1.0
    • Fix Version/s: 1.2.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      Windows XP, Java 5.0 IBM

      Description

      It appears that versions from 1.0 don't handle correctly discriminating objects received from the datastore when the inheritance strategy is set to SINGLE_TABLE.

      Error I receive from test cases (attached):

      <openjpa-1.0.1-r420667:592145 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Cannot load object with id "2". Instance "jpa.Admin-2" with the same id already exists in the L1 cache. This can occur when you assign an existing id to a new instance, and before flushing attempt to load the existing instance for that id.
      FailedObject: jpa.Admin-2

      This problem doesn't occur in OpenJPA version 0.9.7.

      Trace:
      <openjpa-1.0.1-r420667:592145 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Cannot load object with id "2". Instance "jpa.Admin-2" with the same id already exists in the L1 cache. This can occur when you assign an existing id to a new instance, and before flushing attempt to load the existing instance for that id.
      FailedObject: jpa.Admin-2
      at org.apache.openjpa.kernel.BrokerImpl$ManagedCache.add(BrokerImpl.java:4444)
      at org.apache.openjpa.kernel.BrokerImpl.setStateManager(BrokerImpl.java:3779)
      at org.apache.openjpa.kernel.StateManagerImpl.initialize(StateManagerImpl.java:303)
      at org.apache.openjpa.kernel.StateManagerImpl.initialize(StateManagerImpl.java:264)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(JDBCStoreManager.java:330)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initialize(JDBCStoreManager.java:255)
      at org.apache.openjpa.kernel.DelegatingStoreManager.initialize(DelegatingStoreManager.java:111)
      at org.apache.openjpa.kernel.ROPStoreManager.initialize(ROPStoreManager.java:57)
      at org.apache.openjpa.kernel.BrokerImpl.initialize(BrokerImpl.java:843)
      at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:801)
      at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:723)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.find(JDBCStoreManager.java:748)
      at org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.load(RelationFieldStrategy.java:570)
      at org.apache.openjpa.jdbc.meta.FieldMapping.load(FieldMapping.java:802)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:485)
      at org.apache.openjpa.kernel.DelegatingStoreManager.load(DelegatingStoreManager.java:116)
      at org.apache.openjpa.kernel.ROPStoreManager.load(ROPStoreManager.java:78)
      at org.apache.openjpa.kernel.StateManagerImpl.loadFields(StateManagerImpl.java:2867)
      at org.apache.openjpa.kernel.StateManagerImpl.loadField(StateManagerImpl.java:2945)
      at org.apache.openjpa.kernel.StateManagerImpl.beforeAccessField(StateManagerImpl.java:1449)
      at org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1434)
      at jpa.RegularUser.pcGetadmin(RegularUser.java)
      at jpa.RegularUser.getAdmin(RegularUser.java:16)
      at TestCase.testL1ProductEasier(TestCase.java:38)

        Activity

        Hide
        Przemek Koprowski added a comment -

        This is an Eclipse project with JUnit test that fails on this issue.

        In order to run the tests:
        1. Add OpenJPA libraries to the build path.
        2. Change the path in the build.properties file.
        3. Run enchanceWorkspaceAndDeleteDB task from build.xml.
        4. Run TestCase.

        Show
        Przemek Koprowski added a comment - This is an Eclipse project with JUnit test that fails on this issue. In order to run the tests: 1. Add OpenJPA libraries to the build path. 2. Change the path in the build.properties file. 3. Run enchanceWorkspaceAndDeleteDB task from build.xml. 4. Run TestCase.
        Hide
        Russell Parry added a comment -

        I'm not completely sure, as I don't pretend to understand all the code involved, but this seems to be caused by the patch for OPENJPA-313. Specifically, in the block of code starting at line 202 in org.apache.openjpa.jdbc.meta.ClassMapping you can see what changed as part of that patch. If you set a breakpoint while running the failing test case attached here, you can see where everything looks good until we hit line 213 of ClassMapping. At that point, the type changes from jpa.Admin to jpa.RegularUser. It appears to me that this causes the Admin object to get loaded into the L1 cache with an incorrect oid, which causes problems later on.

        cls.getDescribedType() in this same block of code returns the correct "jpa.Admin".

        Changing this block of code back to the way it was before OPENJPA-313 fixes the problem described by this issue.

        However, as I don't claim to fully understand the patch in question, I'm not sure if that causes other problems or if there is some other way to solve OPENJPA-313 without causing the problem shown here.

        Show
        Russell Parry added a comment - I'm not completely sure, as I don't pretend to understand all the code involved, but this seems to be caused by the patch for OPENJPA-313 . Specifically, in the block of code starting at line 202 in org.apache.openjpa.jdbc.meta.ClassMapping you can see what changed as part of that patch. If you set a breakpoint while running the failing test case attached here, you can see where everything looks good until we hit line 213 of ClassMapping. At that point, the type changes from jpa.Admin to jpa.RegularUser. It appears to me that this causes the Admin object to get loaded into the L1 cache with an incorrect oid, which causes problems later on. cls.getDescribedType() in this same block of code returns the correct "jpa.Admin". Changing this block of code back to the way it was before OPENJPA-313 fixes the problem described by this issue. However, as I don't claim to fully understand the patch in question, I'm not sure if that causes other problems or if there is some other way to solve OPENJPA-313 without causing the problem shown here.
        Hide
        Pinaki Poddar added a comment -

        The test case passes on trunk with both runtime and build-time enhanced entities.
        Please reopen if the error continues to appear on trunk.

        Show
        Pinaki Poddar added a comment - The test case passes on trunk with both runtime and build-time enhanced entities. Please reopen if the error continues to appear on trunk.
        Hide
        Przemek Koprowski added a comment -

        I have tested it on release 1.1.0 and on nightly build from 17th of July and the problem persists.

        Show
        Przemek Koprowski added a comment - I have tested it on release 1.1.0 and on nightly build from 17th of July and the problem persists.
        Hide
        Przemek Koprowski added a comment -

        I have tried Russell's solution and it works.

        Show
        Przemek Koprowski added a comment - I have tried Russell's solution and it works.
        Hide
        Przemek Koprowski added a comment -

        It is resolved for trunk (1.2.0), I didn't notice that nightly build on webpage is not updated.

        Show
        Przemek Koprowski added a comment - It is resolved for trunk (1.2.0), I didn't notice that nightly build on webpage is not updated.

          People

          • Assignee:
            Pinaki Poddar
            Reporter:
            Przemek Koprowski
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development