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

Native-Query with multiple joins to same table returning wrong result



    • Bug
    • Status: Open
    • Blocker
    • Resolution: Unresolved
    • 2.1.0, 2.1.1, 2.2.2
    • None
    • jdbc, jpa, kernel, sql
    • None
    • Websphere 8 Runtime and Websphere ApplicationServer and without IBM classes (native TestNG)
      Windows XP
      J2EE 6
      Oracle 11


      The resultset of the following native query should has a result of an objectarray with 3 different returnvalues.
      1) TestEntityIndexReadonly: the holder entity mapped to table indexes
      2) TestEntityCurrencyReadonly: currency mapped to table types
      3) TestEntityTenorReadonly: tenor mapped to table types too

      But i get an Resultset with 3 Objects where the second and the third object are the same (same instance).

      1) TestEntityIndexReadonly:
      2) TestEntityCurrencyReadonly:
      3) TestEntityCurrencyReadonly:

      The Query:
      <named-native-query name="TestEntityIndexReadonly.findByDueDate"
      SELECT id., cur., tenor.*
      FROM indexes id
      LEFT JOIN types cur ON cur.t_id = id.id_t_cur_id
      LEFT JOIN types tenor ON tenor.t_id = id.id_t_tenor_id

      <!-- ResultSets -->
      <sql-result-set-mapping name="TestEntityIndexReadonly.findByDueDateResult">
      <entity-result entity-class="de.test.openjpa.TestEntityIndexReadonly" />
      <entity-result entity-class="de.test.openjpa.TestEntityCurrencyReadonly" />
      <entity-result entity-class="de.test.openjpa.TestEntityTenorReadonly" />

      Hint: For the entity-3 i get the same oid as for entity-2. The reason is, the JDBCStoreManager (Line 1031) "Object oid = base.getObjectId(this, result, null, true, null);" gets the same oid for entity-2 and entity-3.

      I will attache the javaclasses and mapping.xml and a screen from the wrong resultset.

      see also: https://issues.apache.org/jira/browse/openjpa-2218.

      I tried to find out a workaround by removing the abstract parent from TestEntityCurrencyReadonly and TestEntityTenorReadonly.
      In this case, i get the correct Objectinstances but the third entity (TestEntityTenorReadonly) holds the values from TestEntityCurrencyReadonly (also wrong)!

      Hope it helps to find the bug.


        1. TestReadonlyPrimaryKey.java
          2 kB
          axel becker
        2. TestEntityTypeReadonly.java
          2 kB
          axel becker
        3. TestEntityTenorReadonly.java
          0.4 kB
          axel becker
        4. TestEntityIndexReadonly.java
          2 kB
          axel becker
        5. TestEntityImmutableIT.sql
          2 kB
          axel becker
        6. testentityimmutable.jpa.xml
          1 kB
          axel becker
        7. TestEntityCurrencyReadonly.java
          0.4 kB
          axel becker
        8. resultlist.jpeg
          87 kB
          axel becker
        9. debuggscreen with hibernate.jpg
          244 kB
          axel becker



            Unassigned Unassigned
            axel_becker axel becker
            0 Vote for this issue
            1 Start watching this issue