| As depicted in this Jira issue, it's very easy to expect that if we are giving a specific class type to a native SQL query, then HIbernate will do return a List of that particular Java Object type. For example, this query should return a List<Integer>:
List<Integer> results = entityManager.createNativeQuery(
"select p.age from person p", Integer.class )
.getResultList();
Also, we could have a query like this one:
List<Integer[]> results = entityManager.createNativeQuery(
"select p.id, p.age from person p", Integer[].class )
.getResultList();
Therefore, the native query should treat the provided class type as an entity only if the class can be found in the SessionFactory entity metadata. |