I am using JPA in my project.
I came to a query in which I need to make join operation on five tables. So I created a native query which returns five fields.
Unwrap procedure can be performed to assign results to non-entity(which is Beans/POJO). The procedure is as following.
List dtoList = entityManager.createNativeQuery(sql)
.setParameter("userId", userId)
.unwrap(org.hibernate.Query.class).setResultTransformer(Transformers.aliasToBean(JobDTO.class)).list();
The usage is for JPA-Hibernate implementation.