Source:
public List<Object[]> findArrayByGuestbookIdAndDataverseId (Long guestbookId, Long dataverseId, Long limit){ Guestbook gbIn = em.find(Guestbook.class, guestbookId); boolean hasCustomQuestions = gbIn.getCustomQuestions() != null; List<Object[]> retVal = new ArrayList<>(); String queryString = BASE_QUERY_STRING_FOR_PAGE_DISPLAY + " and o.owner_id = " + dataverseId.toString() + " and r.guestbook_id = " + guestbookId.toString(); queryString += " order by r.id desc"; if (limit != null) { queryString += (" limit " + limit); } queryString += ";"; logger.info("search query: "+queryString); List<Object[]> guestbookResults = em.createNativeQuery(queryString).getResultList(); if (guestbookResults == null || guestbookResults.size() == 0) { return retVal; } Map<Long, Object> customQandAs = null; if (hasCustomQuestions) { if (limit == null || guestbookResults.size() < limit) { customQandAs = mapCustomQuestionAnswersAsLists(dataverseId, guestbookId, null, null); } else { customQandAs = mapCustomQuestionAnswersAsLists(dataverseId, guestbookId, (Integer)(guestbookResults.get(0)[0]), (Integer)(guestbookResults.get(guestbookResults.size()-1)[0])); } } for (Object[] result : guestbookResults) { Object[] singleResult = new Object[6]; Integer guestbookResponseId = (Integer)result[0]; singleResult[0] = result[1]; if (result[2] != null){ singleResult[1] = new SimpleDateFormat("MMMM d, yyyy").format((Date) result[2]); } else { singleResult[1] = "N/A"; } singleResult[2] = result[3]; singleResult[3] = result[4]; singleResult[4] = result[5]; if(hasCustomQuestions) { if (customQandAs.containsKey(guestbookResponseId.longValue())) { singleResult[5] = customQandAs.get(guestbookResponseId.longValue()); } } retVal.add(singleResult); } return retVal; }

Target:
public List<Object[]> findArrayByGuestbookIdAndDataverseId (Long guestbookId, Long dataverseId, Long limit){ Guestbook gbIn = em.find(Guestbook.class, guestbookId); boolean hasCustomQuestions = gbIn.getCustomQuestions() != null; List<Object[]> retVal = new ArrayList<>(); String queryString = BASE_QUERY_STRING_FOR_PAGE_DISPLAY + " and o.owner_id = " + dataverseId.toString() + " and r.guestbook_id = " + guestbookId.toString(); queryString += " order by r.id desc"; if (limit != null) { queryString += (" limit " + limit); } queryString += ";"; logger.info("search query: "+queryString); List<Object[]> guestbookResults = em.createNativeQuery(queryString).getResultList(); if (guestbookResults == null || guestbookResults.size() == 0) { return retVal; } Map<Integer, Object> customQandAs = null; if (hasCustomQuestions) { if (limit == null || guestbookResults.size() < limit) { customQandAs = mapCustomQuestionAnswersAsLists(dataverseId, guestbookId, null, null); } else { customQandAs = mapCustomQuestionAnswersAsLists(dataverseId, guestbookId, (Integer)(guestbookResults.get(0)[0]), (Integer)(guestbookResults.get(guestbookResults.size()-1)[0])); } } for (Object[] result : guestbookResults) { Object[] singleResult = new Object[6]; Integer guestbookResponseId = (Integer) result[0]; if (guestbookResponseId != null) { singleResult[0] = result[1]; if (result[2] != null) { singleResult[1] = new SimpleDateFormat("MMMM d, yyyy").format((Date) result[2]); } else { singleResult[1] = "N/A"; } singleResult[2] = result[3]; singleResult[3] = result[4]; singleResult[4] = result[5]; if (hasCustomQuestions) { if (customQandAs.containsKey(guestbookResponseId)) { singleResult[5] = customQandAs.get(guestbookResponseId); } } retVal.add(singleResult); } } return retVal; }