Skip to content

TypeSafeQueryBuilder JoinTypes

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

In addition to the standard join types (Left/LeftFetch/inner/fetch/Right), the TypeSafeQueryBuilder has two more join types.

  • JoinType.Default This join type is used when no join type is specified. When the query is transformed to an HQL query, the actual join type will be decided based on the query configuration.

  • Resolves to Inner if a non-identifier property of the entity was used

  • Resolves to None otherwise, because the foreign key is for free (no join is actually needed)

  • JoinType.None This join type results in using the nested property path in the hql query rather than having the join explicitely.


Example showing default join with non identifier:

query.where(person.getTown().getName()).startsWith("New ");

=> "from Person hobj1 
    join hobj1.town hobj2 
    where hobj2.name like :np1" 
params [np1="New %"]

Example showing default join with only identifier:

query.where(person.getTown().getId()).eq(1L);

=> "from Person hobj1 
    where hobj1.town.id = :np1" 
params [np1=1L]

Example showing explicit None jointype:

Town town = query.join(person.getTown(), JoinType.None);
query.where(town.getName()).startsWith("New ");

=> "from Person hobj1 
    where hobj1.town.name like :np1" 
params [np1="New %"]
Clone this wiki locally