Skip to content

HQL joining with

gert-wijns edited this page Sep 13, 2014 · 2 revisions

In an hql, joins can be filtered in the join declaration using the with literal. This is also supported by the use of query.joinWith(entity).

Though, before you get all exited, hql doesn't allow using any other entity in these restrictions than the joined entity. This dramatically reduces the usefulness of this feature.

Person parent = query.from(Person.class);

Relation childRelation = query.join(parent.getChildRelations());
Person child = childRelation.getChild();
query.joinWith(child).where(child.getName()).eq("Bob");

=> "from Person hobj1 
    join hobj1.childRelations hobj2 
    join hobj2.child hobj3 with hobj3.name = :np1"
params [np1="Bob"]
Clone this wiki locally