UserRolesDAO { public List<UserRoles> listByName(String userName) { Session session = sessionFactory.openSession(); session.beginTransaction(); Criteria criteria = session.createCriteria(UserRoles.class).add(Restrictions.eq("users.username", userName)); List<UserRoles> userRoles = criteria.list(); session.getTransaction().commit(); session.close(); return userRoles; }  List<UserRoles> list(Integer pageNum, Integer numResults); Map<Integer,String> diffRoleList(); List<UserRoles> listByName(String userName); UserRoles minUserRoleId(String userName); Integer totalRecordCount(); UserRoles get(Integer id); Integer insert(UserRoles userRoles); void update(UserRoles userRoles); void delete(Integer id);  }
@Test public void testListByName() throws Exception { List<UserRoles> userRolesList = userRolesDAO.listByName("admin"); LOGGER.info("No. of records fetched:" + userRolesList.get(0).getRole()); }