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

Incorrect relationship data returned when QueryCache and FetchPlans are used.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.1.2, 2.2.2, 2.2.1.1, 2.4.1
    • 2.0.2, 2.1.2, 2.2.1.1, 2.2.3, 2.4.1
    • datacache, jdbc
    • None
    • 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

      Attachments

        1. OPENJPA-2586-2.2.x.patch
          5 kB
          Heath Thomann

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: