I am using JPA in my project.
I came to a query in which I need to make join operation on five tables. So I created a native query which returns five fields.
Since others have already mentioned all the possible solutions, I am sharing my workaround solution.
In my situation with Postgres 9.4
, while working with Jackson
,
//Convert it to named native query.
List list = em.createNativeQuery("select cast(array_to_json(array_agg(row_to_json(a))) as text) from myschema.actors a")
.getResultList();
List map = new ObjectMapper().readValue(list.get(0), new TypeReference>() {});
I am sure you can find same for other databases.
Also FYI, JPA 2.0 native query results as map