ProcessLogDAO { public ProcessLogInfo getLastValue(ProcessLogInfo processLogInfo) { Session session = sessionFactory.openSession(); session.beginTransaction(); try { com.wipro.ats.bdre.md.dao.jpa.Process process = (Process) session.get(Process.class, processLogInfo.getProcessId()); Criteria processLogCriteria = session.createCriteria(ProcessLog.class).add(Restrictions.eq(PROCESS, process)).add(Restrictions.eq("messageId", processLogInfo.getMessageId())).add(Restrictions.eq("logCategory", processLogInfo.getLogCategory())).addOrder(Order.desc("logId")); processLogCriteria.setMaxResults(1); ProcessLogInfo returnProcessLogInfo = new ProcessLogInfo(); if (!processLogCriteria.list().isEmpty()) { ProcessLog processLog = (ProcessLog) processLogCriteria.list().get(0); returnProcessLogInfo.setInstanceRef(processLog.getInstanceRef()); returnProcessLogInfo.setAddTs(processLog.getAddTs()); returnProcessLogInfo.setLogCategory(processLog.getLogCategory()); returnProcessLogInfo.setLogId(processLog.getLogId()); returnProcessLogInfo.setMessage(processLog.getMessage()); returnProcessLogInfo.setMessageId(processLog.getMessageId()); returnProcessLogInfo.setLogCategory(processLog.getLogCategory()); returnProcessLogInfo.setProcessId(processLog.getProcess().getProcessId()); returnProcessLogInfo.setCounter(processLogCriteria.list().size()); } session.getTransaction().commit(); return returnProcessLogInfo; } catch (Exception e) { session.getTransaction().rollback(); LOGGER.info("Error " + e); return null; } finally { session.close(); } }  List<ProcessLog> list(Integer pageNum, Integer numResults); Integer totalRecordCount(); ProcessLog get(Long id); Long insert(ProcessLog processLog); void update(ProcessLog processLog); void delete(Long id); void log(ProcessLogInfo processLogInfo); void logList(List<ProcessLogInfo> processLogInfoList); ProcessLogInfo getLastValue(ProcessLogInfo processLogInfo); List<ProcessLogInfo> listLog(ProcessLogInfo processLogInfo); List<ProcessLogInfo> getProcessLog(ProcessLogInfo processLogInfo); List<ProcessLogInfo> listLastInstanceRef(int processId, String messageId);  }
@Test @Ignore public void testGetLastValue() throws Exception { ProcessLogInfo processLogInfo = new ProcessLogInfo(); processLogInfo.setProcessId(5); processLogInfo.setLogCategory("test"); processLogInfo.setMessage("test"); processLogInfo.setMessageId("test"); processLogInfo.setInstanceRef(Long.parseLong("10")); processLogInfo.setAddTs(new Date()); ProcessLogInfo processLogInfo1 = processLogDAO.getLastValue(processLogInfo); LOGGER.info(" processid of Last inserted process is" + processLogInfo1.getProcessId()); ; }