Using a JPA2 Criteria Query we can project the final result on a DTO (for instance) like this:
query.select(builder.construct( ProductGridDTO.class,
root.get(Productos_.proId),
root.get(Productos_.proAlias),
root.get(Productos_.proNombre),
companies.get(Companias_.ciaNombre),
companies.get(Companias_.ciaId)));
However this method is dependant of the order of arguments in my DTO class, which is plain wrong. Using the old (now deprecated) hibernate criteria API we could use the projection list:
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.property("id"), "id");
projectionList.add(Projections.property("name"), "name");
Which is not dependent of the parameter order of the DTO.
Is it possible to use a similar strategy in JPA?