Skip to content

Selecting TypeSafeValues

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

When you have a TypeSafeValue you can always use the value.select() to get the wrapped value type. The select method will typically return a null value. Its purpose is to record the intent of the use of the value in the query, the return value is not important.

A typical case where this can be used is when using an hql function. These create TypeSafeValues which represent the function which can be used anywhere in the query. By using the select method, these values can be selected into the dto.

House house = query.from(House.class);
TypeSafeValueFunctions fun = query.hqlFunction();

MutablePair<Long, Integer> dto = query.select(MutablePair.class);
dto.setLeft(fun.countDistinct(house.getFloors()).select());
dto.setRight(query.groupBy(house.getFloors()).select());

=> "select count(distinct hobj1.floors) as left, 
           hobj1.floors as right 
    from House hobj1 
    group by hobj1.floors"
Clone this wiki locally