-
Couldn't load subscription status.
- Fork 8
Adding custom HQL to the query
gert-wijns edited this page Sep 13, 2014
·
2 revisions
Custom HQL can be added to the query by making use of the HqlQueryValue or the CustomTypeSafeValue. The CustomTypeSafeValue just wraps a HqlQueryValue.
This is useful when working with a library to generate parts of the query. In any other case it is probably better to create a dedicated TypeSafeValue.
Example group by custom hql:
Building building = query.from(Building.class);
query.select(building.getConstructionDate());
query.setHqlAlias(building, "b");
query.groupBy(new CustomTypeSafeValue<Date>(query,
Date.class, "b.constructionDate"));
=> "select b.constructionDate
from Building b
group by b.constructionDate"Example restricting by a custom hql restriction:
House house = query.from(House.class);
query.where(new HqlQueryValueImpl("hobj1.floors > ?", 10));
=> "from House hobj1 where hobj1.floors > ?" [10]