Instance of super-class not found because of joined subclass reference is an inner join

Description

I have the following model:

1 2 3 4 5 6 7 8 9 10 11 12 13 @Entity class Department { ... } @Entity @Table(name = "Users") @Inheritance(strategy = InheritanceType.JOINED) class User { ... } @Entity class Customer extends User { @ManyToOne(optional=false) Department belongTo; }

em.find(Customer.class, id) generates following sql:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 select customer0_.id as id1_2_0_, customer0_1_.name as name2_2_0_, customer0_.belongTo_id as belongTo2_0_0_, department1_.id as id1_1_1_, department1_.name as name2_1_1_ from Customer customer0_ inner join Users customer0_1_ on customer0_.id=customer0_1_.id inner join Department department1_ on customer0_.belongTo_id=department1_.id where customer0_.id=?

The code above works fine, the customer instance is found.

em.find(User.class, id) generates following sql (should return)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 select user0_.id as id1_2_0_, user0_.name as name2_2_0_, user0_1_.belongTo_id as belongTo2_0_0_, case when user0_1_.id is not null then 1 when user0_.id is not null then 0 end as clazz_0_, department1_.id as id1_1_1_, department1_.name as name2_1_1_ from Users user0_ left outer join Customer user0_1_ on user0_.id=user0_1_.id inner join Department department1_ on user0_1_.belongTo_id=department1_.id where user0_.id=?

The code above does not work (instance of user not found) since Department join is an inner join. This was not the behavior of earlier versions 3.3.x.

See attached code for complete code and tests.

Environment

None

Status

Assignee

Steve Ebersole

Reporter

Tony Dalbrekt

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Priority

Major