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

Incorrect relationship data returned when QueryCache and FetchPlans are used.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.1.2, 2.2.2, 2.2.1.1, 2.4.1
    • Fix Version/s: 2.0.2, 2.1.2, 2.2.1.1, 2.2.3, 2.4.1
    • Component/s: datacache, jdbc
    • Labels:
      None
    • Flags:
      Patch

      Description

      I have found a scenario that the wrong data is returned when the DataCache, QueryCache, and FetchPlans are used. To explain, take these very simple entities and relationship:

      @Entity
      public class Entity1 {
      @Id
      private int id;

      @OneToOne(fetch = FetchType.LAZY)
      private Entity2 ent2;
      ........

      @Entity
      public class Entity2 {
      @Id
      private Long id;
      ......

      Given these two entities, take this scenario:

      Query q = em.createQuery("Select e1 from Entity1 e1");
      FetchPlan fetchPlan = q.unwrap(OpenJPAQuery.class).getFetchPlan();
      fetchPlan.addField(Entity1.class, "ent2");
      List<Entity1> results = (List<Entity1>) q.getResultList();

      em.clear();

      assertNotNull("No results returned!", results);
      for (Entity1 e1 : results)

      { assertNotNull("An 'Entity2' should have been returned!", e1.getEnt2()); }

      With this code, assume the DataCache and QueryCache are both enabled, and assume there is an Entity1 with an Entity2 in the database. When we execute this code all works fine. However, if we execute the code back to back using the same EntityManagerFactory, an Entity1 will be returned but its Entity2 will be null! If on the other hand, we execute the code 3 times in a row, where there is a time lag between the 2nd and 3rd execution greater than the DataCache timeout, the correct data will be returned during the 3rd execution. This shows that there is a problem when the DataCache, QueryCache, and a FetchPlan are used. For more details please see the patch I've attached which contains a test to recreate this issue as well as a proposed fix.

      Thanks,

      Heath Thomann

        Activity

        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1702137 from Heath Thomann in branch 'openjpa/branches/2.0.x'
        [ https://svn.apache.org/r1702137 ]

        OPENJPA-2586: Fix to return proper relationship data when QueryCache and FetchPlans are used.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1702137 from Heath Thomann in branch 'openjpa/branches/2.0.x' [ https://svn.apache.org/r1702137 ] OPENJPA-2586 : Fix to return proper relationship data when QueryCache and FetchPlans are used.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1702142 from Heath Thomann in branch 'openjpa/branches/2.1.x'
        [ https://svn.apache.org/r1702142 ]

        OPENJPA-2586: Fix to return proper relationship data when QueryCache and FetchPlans are used.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1702142 from Heath Thomann in branch 'openjpa/branches/2.1.x' [ https://svn.apache.org/r1702142 ] OPENJPA-2586 : Fix to return proper relationship data when QueryCache and FetchPlans are used.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1702143 from Heath Thomann in branch 'openjpa/branches/2.2.x'
        [ https://svn.apache.org/r1702143 ]

        OPENJPA-2586: Fix to return proper relationship data when QueryCache and FetchPlans are used.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1702143 from Heath Thomann in branch 'openjpa/branches/2.2.x' [ https://svn.apache.org/r1702143 ] OPENJPA-2586 : Fix to return proper relationship data when QueryCache and FetchPlans are used.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1702145 from Heath Thomann in branch 'openjpa/branches/2.2.1.x'
        [ https://svn.apache.org/r1702145 ]

        OPENJPA-2586: Fix to return proper relationship data when QueryCache and FetchPlans are used.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1702145 from Heath Thomann in branch 'openjpa/branches/2.2.1.x' [ https://svn.apache.org/r1702145 ] OPENJPA-2586 : Fix to return proper relationship data when QueryCache and FetchPlans are used.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1702147 from Heath Thomann in branch 'openjpa/trunk'
        [ https://svn.apache.org/r1702147 ]

        OPENJPA-2586: Fix to return proper relationship data when QueryCache and FetchPlans are used.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1702147 from Heath Thomann in branch 'openjpa/trunk' [ https://svn.apache.org/r1702147 ] OPENJPA-2586 : Fix to return proper relationship data when QueryCache and FetchPlans are used.

          People

          • Assignee:
            jpaheath Heath Thomann
            Reporter:
            jpaheath Heath Thomann
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development