With an entity hierarchy as souch:
A B extends A C1 extendes B C2 extends B D extends C1
creating a query using treat:
{code:java}select A from A where treat(b as B).property = 'something';{code}
the generated sql will be:
{code: java sql }select ... from A where DTYPE in ('C2' , 'D' ) and ...{code}
C1 and B are missing, but should be there, since they are not Abstract.
The culprit is this line of code: [https://github.com/hibernate/hibernate-orm/blob/6acfd17548ac1ccfd9af6404965a8719c94d705c/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java#L635|https://github.com/hibernate/hibernate-orm/blob/6acfd17548ac1ccfd9af6404965a8719c94d705c/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java#L635]
{code:java}if ( !actualQueryable.hasSubclasses() ) { values.add( actualQueryable.getDiscriminatorSQLValue() ); }{code}
the subclass should be excluded from the query only if the entity is Abstract |
|