Uploaded image for project: 'Hibernate ORM'
  1. HHH-9637

Join is reused when 2 explicit joins are used for the same ToOne association

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 4.2.16
    • Fix Version/s: 4.2.20, 5.0.0.CR3, 4.3.11
    • Component/s: query-hql
    • Labels:
      None

      Description

      The bug was introduced by HHH-9305 Closed .

      Example:
      Tree entities with OneToOne association:
      person <> address <> country

      We are using JPA criteria that's why we cannot use fetch in the where clause. So we are doing the following:

      select persion
      from Persion as persion
      inner join persion.address as address_filter
      inner join fetch persion.address as address
      inner join fetch address.country
      where
      address_filter.city_name = 'some value';
      

      After HHH-9305 Closed changes it reuses the first fetch and query (during parsing) is become as this:

      select persion
      from Persion as persion
      inner join persion.address as address_filter
      inner join fetch address.country
      where
      address_filter.city_name = 'some value'
      

      Because it cannot found parent for country fetch it throws an error:
      org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list

      Since I cannot imagine a case where I need to do join twice in OneToOne associations except for fetching I think it's ok to reuse join here but for this case it should be the second join (with fetch option).

      I have found a good workaround.

      select persion
      from Persion as persion
      inner join fetch persion.address as address
      inner join fetch address.country
      where
      persion.address.city_name = 'some value';
      

      This query can be converted to JPA criteria query and will do exactly the same thing without any errors.

        Attachments

          Issue links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: