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

Recursively embedded entities generate an extra and reduntant SQL call to the database.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.1.0
    • jdbc
    • None

    Description

      Consider the following persistent class model. The accessor methods are removed for the sake of brevity.

      public class EmbeddedOwnerPC {

      private int id1;
      private int id2;
      private String stringField;
      private EmbeddedPC embedded;
      private ComplexEmbeddedPC complexEmbedded;
      }

      public class EmbeddedPC {
      private int intField;
      private String stringField;
      }

      public class ComplexEmbeddedPC extends RecursivelyEmbeddedPC {

      private String stringField;
      private EmbeddedOwnerPC ownerField;
      private Set stringSet = new HashSet();
      }

      public class RecursivelyEmbeddedPC {

      private EmbeddedPC embedded;
      }

      When trying to retrieve the EmbeddedOwner entity with a given fetch plan that includes the complexEmbedded and the embedded fields in the RecursivelyEmbeddedPC class it generate the following 2 SQL statements to load the entity.

      SELECT t0.TYP, t0.VERSN, t0.EMBEDDED_NULL, t0.ID1, t0.ID2, t0.INTFIELD1,
      t0.STRINGFIELD3, t0.STRINGFIELD FROM EMBEDDEDOWNERPC t0 WHERE t0.ID1 = ? AND t0.ID2 = ? FOR UPDATE

      SELECT t0.ID1, t0.ID2 FROM EMBEDDEDOWNERPC t0 WHERE t0.ID1 = ? AND t0.ID2 = ?
      FOR UPDATE

      The second call is reduntant and not needed. The fix is to the EmbedFieldStrategy class load method to ensure that all fields that are required to be loaded as per the fetch plan and included from the result set and ONLY when this is not true then generate the extra call otherwise return a hollow embedded entity. In the above test case the extra call was generated to get the stringSet field which was not specified in the fetch plan but the call is made out nevertheless which just selects the primary keys with the same where clause.

      Attachments

        1. OPENJPA-576-v2.patch
          2 kB
          Sandeep Shrivastava
        2. OPENJPA-576-v2.patch
          3 kB
          Sandeep Shrivastava
        3. OPENJPA-576.patch
          2 kB
          Sandeep Shrivastava

        Activity

          People

            Unassigned Unassigned
            sandeeps@bea.com Sandeep Shrivastava
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 24h
                24h
                Remaining:
                Remaining Estimate - 24h
                24h
                Logged:
                Time Spent - Not Specified
                Not Specified