Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 9.0pe
    • Fix Version/s: 9.0pe_dev
    • Component/s: entity-persistence
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      365

      Description

      TopLink EJBQL parser transalates EJBQL query with subselect into a wrong
      ReportQuery.

      Example:

      Class Employee has OneToMany relation to class PhoneNumber:
      @Entity
      public class Employee implements Serializable {
      private Integer id;
      private Collection<PhoneNumber> phoneNumbers;
      ...
      @OneToMany(cascade=ALL, mappedBy="owner")
      public Collection<PhoneNumber> getPhoneNumbers()

      { return phoneNumbers; }

      ...
      }

      @Entity
      public class PhoneNumber implements Serializable {
      private String type;
      private Employee owner;
      ...
      @ManyToOne
      @JoinColumn(name="OWNER_ID", referencedColumnName="EMP_ID")
      public Employee getOwner()

      { return owner; }

      ...
      }

      EJBQL query:
      "SELECT e FROM Employee e WHERE EXISTS (SELECT p FROM e.phoneNumbers p where
      p.type = 'Home')"

      The correct translation of the EJBQL query into TopLink ReportQuery would look
      like the following:
      ExpressionBuilder builder = new ExpressionBuilder();
      ReportQuery reportQuery = new ReportQuery(Employee.class, builder);
      ExpressionBuilder innerBuilder = new ExpressionBuilder();
      ReportQuery innerQuery = new ReportQuery(PhoneNumber.class, innerBuilder);
      Expression innerExp = innerBuilder.get("type").equal("Home").and
      (innerBuilder.get("owner").get("id").equal(builder.get("id")));
      innerQuery.setSelectionCriteria(innerExp);
      Expression exp = builder.exists(innerQuery);
      reportQuery.setSelectionCriteria(exp);
      reportQuery.addItem("", builder);

        Activity

        Hide
        ailitche added a comment -

        Another possible (and actually more simple) approach is:

        Expression innerExp = builder.anyOf("phoneNumbers").get("type").equal("Home");

        But currently translation incorrectly does:

        Expression innerExp = innerBuilder.anyOf("phoneNumbers").get("type").equal
        ("Home");

        Which of course causes InvalidQuereyKeyException (because innerBuilder is
        associated with PhoneNumber, not Employee).

        Show
        ailitche added a comment - Another possible (and actually more simple) approach is: Expression innerExp = builder.anyOf("phoneNumbers").get("type").equal("Home"); But currently translation incorrectly does: Expression innerExp = innerBuilder.anyOf("phoneNumbers").get("type").equal ("Home"); Which of course causes InvalidQuereyKeyException (because innerBuilder is associated with PhoneNumber, not Employee).
        Hide
        mb124283 added a comment -

        Started looking into this.

        Michael

        Show
        mb124283 added a comment - Started looking into this. Michael
        Hide
        mb124283 added a comment -
            • Issue 140 has been marked as a duplicate of this issue. ***
        Show
        mb124283 added a comment - Issue 140 has been marked as a duplicate of this issue. ***
        Hide
        mb124283 added a comment -

        Changed the code in EJB QL ParseTree in case the FROM clause of the subquery
        defines an identification variable on a collection relationship field, such as
        e.phoneNumbers p in the above example. Now it takes the reference class of 'e'
        and its ExpressionBuilder for the subquery.

        Show
        mb124283 added a comment - Changed the code in EJB QL ParseTree in case the FROM clause of the subquery defines an identification variable on a collection relationship field, such as e.phoneNumbers p in the above example. Now it takes the reference class of 'e' and its ExpressionBuilder for the subquery.
        Hide
        mb124283 added a comment -

        Added target milestone.

        Show
        mb124283 added a comment - Added target milestone.

          People

          • Assignee:
            mb124283
            Reporter:
            ailitche
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: