We're updating the issue view to help you get more done. 

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

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.

Environment

Otacle Linux 6.5 64 Bit (VirtualBox VM on Windows 7 Pro 64)
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
Hibernate 4.3.6.Final (also 4.3.5 in WildFly 8.1 Final)
H2 1.4.181 In-memory

Status

Assignee

Brett Meyer

Reporter

Jim Nicolson

Labels

None

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

backportReEvaluate

None

Components

Fix versions

Affects versions

4.3.6
4.3.5

Priority

Major