JPA 2.0 native query results as map

Which JPA are you using – Hibernate, EclipseLink or something else?

There is no standard way to do this in JPA but your specific implementation may allow it – for example, Eclipselink has a query result type hint.

http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg03013.html

Query query = entityManager.createNativeQuery(sql);
query.setHint(QueryHints.RESULT_TYPE, ResultType.Map);

For Hibernate, with javax.persistence.Query dbQuery:

org.hibernate.Query hibernateQuery =((org.hibernate.jpa.HibernateQuery)dbQuery)
.getHibernateQuery();
hibernateQuery.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);

Leave a Comment