FileDAO { public List<com.wipro.ats.bdre.md.beans.FileInfo> getFiles(long minBatchId, long maxBatchId) { Session session = sessionFactory.openSession(); List<FileInfo> fileInfos = new ArrayList<FileInfo>(); try { session.beginTransaction(); Criteria joinFileServers = session.createCriteria(File.class, "f").createAlias("f.servers", "s").add(Restrictions.between("f.batch.batchId", minBatchId, maxBatchId)); joinFileServers.addOrder(Order.asc("f.batch.batchId")); List<File> joinedFileServerList = joinFileServers.list(); LOGGER.info(joinedFileServerList.toString()); for (File file : joinedFileServerList) { FileInfo fileInfo = new FileInfo(); fileInfo.setBatchId(file.getBatch().getBatchId()); fileInfo.setFilePath(file.getId().getPath()); fileInfo.setFileHash(file.getId().getFileHash()); fileInfo.setFileSize(file.getId().getFileSize()); fileInfo.setServerIP(file.getServers().getServerIp()); fileInfo.setServerName(file.getServers().getServerName()); fileInfo.setServerType(file.getServers().getServerType()); fileInfo.setSshPrivateKey(file.getServers().getSshPrivateKey()); fileInfo.setUsername(file.getServers().getLoginUser()); fileInfo.setPassword(file.getServers().getLoginPassword()); fileInfo.setServerMetaInfo(file.getServers().getServerMetainfo()); fileInfos.add(fileInfo); LOGGER.info("fileInfo added with Batch ID:" + fileInfo.getBatchId()); } session.getTransaction().commit(); return fileInfos; } catch (MetadataException e) { session.getTransaction().rollback(); LOGGER.info("Error Occured " + e); return fileInfos; } finally { session.close(); } }  List<File> list(Integer pageNum, Integer numResults); Long totalRecordCount(); File get(FileId fileId); FileId insert(File file); com.wipro.ats.bdre.md.beans.table.File update(com.wipro.ats.bdre.md.beans.table.File tableFile); void delete(Long batchId); List<com.wipro.ats.bdre.md.beans.FileInfo> getFiles(long minBatchId, long maxBatchId); com.wipro.ats.bdre.md.beans.table.File getFile(com.wipro.ats.bdre.md.beans.table.File file); com.wipro.ats.bdre.md.beans.table.File insert(com.wipro.ats.bdre.md.beans.table.File tableFile);  }
@Test public void testGetFiles() throws Exception { List<FileInfo> fileInfos = fileDAO.getFiles(0, 1); for (FileInfo fileInfo : fileInfos) { LOGGER.info("file Info is " + fileInfo); } }