4

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 with parent via join table. Parent don't have Agg object.

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

How can I now join Child2 with Agg, without causing join with all subclasses tables. I simple want to join only with Child2 table (without joining with Child2, Child3, Child4)

I was trying to use 'class' property (i.e. ch2.class =...) the result is correct, but generated query contains join to every subclasses ;/

HQL "From Agg a Join a.l" also join with all sub-classes (even with ch2.class)

Thanks!

4

1 回答 1

0

您可以使用交叉连接来解决此问题,因为 DBMS 无论如何都会将其优化为内部连接。像这样的东西SELECT ch2, agg FROM Child2 ch2, Agg agg WHERE ch2.joinField = agg.id AND ch2.field1 =... AND ch2.field2 =...

于 2017-03-12T19:11:24.907 回答