How to get value of some fields in a native query (JPA)?
For example I want to get name and age of customer table:
Query q = em.createNativeQuery("SELECT name,age FROM customer WHERE id=...");
Note: I don’t want to map results to entities. I just want to get the value of the field.
Thanks
A native query with multiple select expressions returns an
Object[](orList<Object[]>). From the specification:So, to get the name and age in your example, you’d have to do something like this:
References