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

Incorrect SQL generated for Polymorpic Queries involving TYPE() with @Inheritance(strategy=InheritanceType.JOINED)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.3.5, 4.3.6
    • Fix Version/s: 5.0.7
    • Component/s: query-hql
    • Labels:
      None
    • Environment:

      Description

      For @Inheritance(strategy=InheritanceType.JOINED), three forms of polymorphic queries involving TYPE() generated bad SQL Statements involving outer joins.

      These queries execute correctly for @Inheritance(strategy=InheritanceType.SINGLE_TABLE)

      EXAMPLE OF FAILURE:

      e.g. for
      public static final String JPQL_QUERY_FIND_ALL_PERSONS_USING_IN =
      "SELECT p"
      + " FROM Party p"
      + " WHERE TYPE (p) IN ("
      + " Person"
      + " )";

      The generated SQL fails as below:

      Hibernate:
      select
      party0_.id as id2_1_,
      ...
      from
      Party party0_
      left outer join
      Person party0_1_
      on party0_.id=party0_1_.id
      left outer join
      Organisation party0_2_
      on party0_.id=party0_2_.id
      where
      case
      when party0_1_.id is not null then Person
      when party0_2_.id is not null then Organisation
      when party0_.id is not null then 'Party'
      end='Person'
      Aug 23, 2014 2:26:43 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
      WARN: SQL Error: 42122, SQLState: 42S22
      Aug 23, 2014 2:26:43 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
      ERROR: Column "PERSON" not found; SQL statement:

      EXAMPLE PROJECT:
      Exported Eclipse m2e example project/test (source only) attached.

        Attachments

          Issue links

            Activity

              People

              • Votes:
                3 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: