treat() operator for collection join generates SQL without discriminator condition

Description

When I narrow a many-to-one association using treat(), like this:

select p.name from Person p join treat(p.emergencyContact as Employee) c

then the generated SQL looks like this:

select person0_.name as col_0_0_ from Person person0_ inner join Person person1_ on person0_.emergencyContact_id=person1_.id and person1_.DTYPE='Employee'

And correctly includes the discriminator condition person1_.DTYPE='Employee'.

But when I narrow a collection like this:

select p.name from Person p join treat(p.contacts as Employee) c"

Then the discriminator condition is missing from the SQL:

select person0_.name as col_0_0_ from Person person0_ inner join Person_Person contacts1_ on person0_.id=contacts1_.Person_id inner join Person person2_ on contacts1_.contacts_id=person2_.id

Environment

None

Assignee

Unassigned

Reporter

Gavin King

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Priority

Major
Configure