HQL - merging with only one subclass

My model (InheritanceType.JOINED):

class Parent{...} class Child1 extends Parent{...} class Child2 extends Parent{...} class Child3 extends Parent{...} class Child4 extends Parent{...} class Agg{ List<Parent> l; } 

Agg is connected to the parent through a connection table. The parent does not have an Agg object.

I am doing filtering on Child2 ie: "From Child2 ch2 WHERE ch2.field1 = ... ch2.field2 = ... etc."

How can I now join Child2 with Agg without causing joins to all subclass tables. I just want to join only the Child2 table (without joining Child2, Child3, Child4)

I tried to use the "class" property (ie ch2.class = ...), the result is correct, but the generated query contains a union for each subclass; /

The HQL "From Agg a Join al" is also merged with all subclasses (even with ch2.class)

Thanks!

+4
source share
1 answer

You can use cross-connection to solve this problem, because the DBMS optimizes this for the internal connection anyway. Something like this SELECT ch2, agg FROM Child2 ch2, Agg agg WHERE ch2.joinField = agg.id AND ch2.field1 =... AND ch2.field2 =...

0
source

Source: https://habr.com/ru/post/1441157/


All Articles