@SqlResultSetMappings({ @SqlResultSetMapping(name = "alertMapping", columns = { @ColumnResult(name = "accountId")}) }) @NamedNativeQuery(name = "alert", query = " select distinct c.accountId from account c ", resultSetMapping = "alertMapping")
Using:
EntityManager em = ...... / injected / etc TypedQuery<String> query = em.createNamedQuery("alert", String.class); List<String> accountIds = query.getResultList();
(unchecked syntax, but I hope the main idea comes)
For NamedNativeQueries, you can use resultClass only when the result is actually mapped to Entity. It is also possible not to specify a comparison of results, in which case you will get the List object [] back. Each list item will be a single entry, and you will need to explicitly point each object to the type that you need. Hm, the last part may be available only for NativeQueries, not Named - sorry, unsure at the moment.
source share