The way you’re constructing this multiselect Criteria Query is wrong - you are creating a query to get the Root, than creating another query and re-using that root object there without specifying a from. I'm afraid this used to work in Hibernate 5 by chance, but even JPA's AbstractQuery#getRoots() javadoc says:
… Modifications to the set do not affect the query.
The correct way to do this in your reproducer would be something like this:
CriteriaQuery<TestDto> queryMulti = criteriaBuilder.createQuery(TestDto.class);
Root<TestTbl> root = queryMulti.from(TestTbl.class);
CriteriaQuery<?> multiselect = queryMulti.multiselect(root.get(TestTbl_.id));
Closing this issue as the behavior in Hibernate 6 is consistent with the spec. If you have any additional doubt or request feel free to leave a comment. |