-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: collecting hibernate Query result into Map<String, String>
PostPosted: Fri Jan 07, 2011 3:09 am 
Newbie

Joined: Fri Jan 07, 2011 3:04 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.