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

Was it helpful?

Solution

That can be done via CriteriaBuilder.construct. First argument is class of result, following arguments are Selections.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top