i want to store name and id of HQL query result into a Hashmap . here is my code. is there any better way to do it?
String hql = "FROM Student";
Session session = HibernateUtil.getSessionFactory().openSession();
Query query = session.createQuery(hql);
List queryResults = query.list();
List<Student> result = new ArrayList<Student>();
Iterator it = queryResults.iterator();
while (it.hasNext()) {
Student student = (Student) it.next();
result.add(student);
}
Map mapresult = new LinkedHashMap<Integer,String>();
for (Student Maprslt : result)
mapresult.put(Maprslt.getId(), Maprslt.getName());