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

N+1 select when eager fetching two collection fields of the same entity type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.2.1, 2.3.0
    • None
    • jdbc, jpa, performance
    • None

    Description

      I have a ProductOrder entity that has two @OneToMany lists of ProductOrderLines. When selecting from ProductOrder, eager fetching does not seem to recurse into the second list so that each field of each ProductOrderLine in the second list is fetched using a separate "load field" operation.

      The problem does not occur when there is only one List.

      @Entity
      public class ProductOrder {
      @JoinColumn(name = "PLANNED_ORDER_ID")
      @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
      private List<ProductOrderLine> plannedOrderLines = new ArrayList<ProductOrderLine>();

      @JoinColumn(name = "ACTUAL_ORDER_ID")
      @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
      private List<ProductOrderLine> actualOrderLines = new ArrayList<ProductOrderLine>();

      Expected nr of queries: 1 (for Order) + 1 (for Order.plannedOrderLines) + 1 (for Order.actualOrderLines).
      Actual nr of queries: same as expected + 1 query for each field of each ProductOrderLine in Order.actualOrderLines.

      Same problem exists when using @JoinTable instead of @JoinColumn (JPA 2.0 only).

      Attachments

        1. OPENJPA-2299-tests.zip
          5 kB
          Vermeulen

        Activity

          People

            Unassigned Unassigned
            slowstrider Vermeulen
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: