| Hi, I want to collect the results of a query into hashMap instead of list.
 This is my Query:
 
 String SQL_QUERY = "select subject, topicID from TracPojo where subject LIKE '%" + subject + "%'";
 
 I need to store the subject as key and topicID as value of the hashMap. Is there any way to achieve this.
 
 This is my code:
 
 public Map<String, String> getResultsMapBySubjectandTopicID(String subject1) {
 Map<String, String> resultsMap = new HashMap<String, String>();
 Session session = HibernateUtil.getSessionFactory().openSession();
 String subject = subject1.toUpperCase();
 
 String SQL_QUERY = "select subject, topicID from TracPojo where subject LIKE '%" + subject + "%'";
 
 Query query = session.createQuery(SQL_QUERY);
 
 List<Object[]> l1 = query.list();
 if (l1.size() > 0) {
 for(int i=0;i<l1.size();i++){
 resultsMap.put((String)l1.get(i)[0], (String)l1.get(i)[1]);
 }
 }
 return resultsMap;
 }
 
 This is not giving me the result. Help me to resolve this issue.
 
 Thank you,
 Veerendra
 
 
 |