That can be done via CriteriaBuilder.construct. First argument is class of result, following arguments are Selections.
Map to non managed entity with criteria-api
-
26-06-2022 - |
Question
In JPA1 you could map a result to a non-managed entity by something like this:
Query query = entityManager.createQuery("SELECT NEW com.test.TestInfo(e.name, e.city) from Example e");
In JPA2 you could do it like this :
Query query = entityManager.createQuery(“SELECT e.name, e.city from Example e”,TestInfo.Class);
How would I do that with the criteria-api? I simply don't know the buzzwords to google for.
Any hints?
Jonny
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow