I'm playing with JPA criteria and result transformers, inspired by https://vladmihalcea.com/why-you-should-use-the-hibernate-resulttransformer-to-customize-result-set-mappings/
Using the criteria builder, I can define a result transformer to my query when I only use a single select:
The IdResultTransformer creates the IdDTO, this works fine.
However, when I want to expand the projected fields to more than one column using a multiselect
where UserTransformer has two fields, "id" and "name", I cannot do this by using the result transformer because
the query automatically uses "new" in the statement, so I cannot use a result transformer here. The only solution is the to use
which requires me to have an appropriate constructor here. using createQuery also forces me to decide quite early the resulting object class, which is IMHO not necessarily very convenient:
a) Requires code refactoring, especially for legacy criteria code
b) the "new" constructor detection does not work for static inner classes, I have to move UserDTO to top level.