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

SubQuery with Exists generates invalid SQL

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Duplicate
    • 1.0.2, 1.0.3, 1.1.0, 1.2.0
    • None
    • query
    • None
    • Windows XP, JDK 1.6.0_07, Derby and HSQL.

    Description

      When using a subquery containing EXISTS, the generated SQL contains table aliases that does not exist in the select statement. For example, the following query:

      SELECT new test.dto.EmployeeReportDTO(e.name, a.city)
      FROM Employee e JOIN e.address a
      WHERE e.name LIKE :name
      AND EXISTS (SELECT p.number from PhoneNumber p WHERE p.owner = e)

      will cause the following exception:

      Column not found: T3.CITY in statement [SELECT t0.name, t3.city FROM Employee t0 INNER JOIN Address t1 ON t0.address_id = t1.id WHERE (t0.name LIKE ? ESCAPE '\' AND NOT (EXISTS (SELECT t2.number FROM Address t1, PhoneNumber t2 WHERE (t2.owner_id = t0.id))))]

      Attachments

        1. openjpa-bug.zip
          6 kB
          Bjorn Beskow
        2. openjpa-bug.zip
          6 kB
          Bjorn Beskow

        Issue Links

          Activity

            People

              mikedd Michael Dick
              beskow Bjorn Beskow
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: