I am creating generic reporting logic for my application and want to be able to run any query and parse the responses. The inputs for the reporting are native SQL queries that I run using EntityManager.createNativeQuery(query).
I have all of this working fine, but currently I have to also indicate the return “headings” for the query response.
For example, for this query:
SELECT name, email FROM users;
I need to know that I’m getting back the name and email from the query. All I get back from running the query is a List of String arrays. Somehow, I’d like to be able to get back an array or list that has [“name”, “email”] for this particular query.
I’m not seeing a way to interrogate the Query object to find out this information. I also don’t see any indication of this data in the response. Is there a way to get at this data in JPA?
For specifics, the implementation I’m using is EclipseLink.
Thanks.
EclipseLink also allows native queries to return Maps instead of Object[].
Use the “eclipselink.result-type” hint.
“eclipselink.result-type”=”Map”