InstanceExecDAO { public List<com.wipro.ats.bdre.md.beans.table.InstanceExec> list(Integer processId, Integer pageNum, Integer numResults) { Session session = sessionFactory.openSession(); session.beginTransaction(); List<InstanceExec> instanceExeces = new ArrayList<InstanceExec>(); List<Batch> batchList = new ArrayList<Batch>(); List<com.wipro.ats.bdre.md.beans.table.InstanceExec> instanceExecList = new ArrayList<com.wipro.ats.bdre.md.beans.table.InstanceExec>(); Integer counter; try { if (processId == null) { counter = session.createCriteria(InstanceExec.class).list().size(); Criteria joinBatchInstanceExec = session.createCriteria(InstanceExec.class).addOrder(Order.desc("instanceExecId")); joinBatchInstanceExec.setFirstResult(pageNum); joinBatchInstanceExec.setMaxResults(numResults); instanceExeces = joinBatchInstanceExec.list(); } else { counter = session.createCriteria(InstanceExec.class).add(Restrictions.eq("process.processId", processId)).list().size(); Criteria joinBatchInstanceExec = session.createCriteria(Batch.class, "b").createAlias("b.instanceExec", "ieid", JoinType.RIGHT_OUTER_JOIN).add(Restrictions.eq("ieid.process.processId", processId)).addOrder(Order.desc("ieid.instanceExecId")); joinBatchInstanceExec.setFirstResult(pageNum); joinBatchInstanceExec.setMaxResults(numResults); batchList = joinBatchInstanceExec.list(); } LOGGER.info("size of instanceExec:" + instanceExeces.size()); LOGGER.info("size of list:" + batchList.size()); LOGGER.info("counter:" + counter); for (Batch batch : batchList) { if (batch != null && batch.getInstanceExec() != null) { LOGGER.info("instanceExec:" + batch.getInstanceExec().getInstanceExecId()); instanceExeces.add(batch.getInstanceExec()); } } for (com.wipro.ats.bdre.md.dao.jpa.InstanceExec jpaInstanceExec : instanceExeces) { com.wipro.ats.bdre.md.beans.table.InstanceExec instanceExec = new com.wipro.ats.bdre.md.beans.table.InstanceExec(); instanceExec.setInstanceExecId(jpaInstanceExec.getInstanceExecId().intValue()); instanceExec.setProcessId(jpaInstanceExec.getProcess().getProcessId()); instanceExec.setExecState(jpaInstanceExec.getExecStatus().getExecStateId()); instanceExec.setStartTs(jpaInstanceExec.getStartTs()); instanceExec.setEndTs(jpaInstanceExec.getEndTs()); instanceExec.setCounter(counter); instanceExecList.add(instanceExec); } session.getTransaction().commit(); } catch (MetadataException e) { session.getTransaction().rollback(); LOGGER.error(e); } finally { session.close(); } return instanceExecList; }  List<com.wipro.ats.bdre.md.beans.table.InstanceExec> list(Integer processId, Integer pageNum, Integer numResults); InstanceExec getLatestExecofProcess(Integer processId); Long totalRecordCount(); InstanceExec get(Long id); Long insert(InstanceExec instanceExec); void update(InstanceExec instanceExec); void delete(Long id); List<SLAMonitoringBean> slaMonitoringData(List<Process> subProcessList);  }
@Ignore @Test public void testList() throws Exception { LOGGER.info("Size of InstanceExec is atleast:" + instanceExecDAO.list(null, 0, 10).size()); }