I have a complex sql query that joins 7 tables and returns 110 columns. I am trying to use native query created using shared entity manager. Not sure how to map the resultset to a POJO. Mapping each column to resultset object array works, but is very inefficient in terms of lines of code. Any suggestion how to map it or any other way I can perform this?
Here's some pseudo code I have implemented:
Query query = sharedEntityManager.createNativeQuery(
" select a.c1, a.c2,.., b.c1, b.c2,.., c.c1, c.c2,...
from atab a, btab b, ctab c, ...
where condition1, condition2,...");
query.setParameter("param1", param1);
List<Object[]> results = query.getResultList();
List<CustomPojo> retList = new ArrayList<>();
for(Object[] obj : results){
CustomPojo row = new CustomPojo();
row.setF1(obj[0].toString());
row.setF2(obj[1].toString());
...
...
retList.add(row);
}
return retList;