// set transformer, if necessary
List<? extends Expression<?>> projection = getMetadata().getProjection();
if (projection.size() == 1 && !forCount) {
Expression<?> expr = projection.get(0);
if (expr instanceof FactoryExpression<?>) {
query.setResultTransformer(new FactoryExpressionTransformer((FactoryExpression<?>) projection.get(0)));
}
} else if (!forCount) {
FactoryExpression<?> proj = FactoryExpressionUtils.wrap(projection);
if (proj != null) {
query.setResultTransformer(new FactoryExpressionTransformer(proj));
}
}
return query;
}