I have a user table, how do I create a Criteria in Hibernate that returns a Map with the UserId as the key and the User object as the value?
I have a user table, how do I create a Criteria in Hibernate that
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t think this is possible, cause a query always returns a List: http://docs.jboss.org/hibernate/orm/3.2/api/org/hibernate/Criteria.html#list()
or in a special case a single element.
There is just no method that could return a map.
So without hacks like overwriting the Session to create a special Criteria which also has a map() method you can’t do what you want.
Just return a list and convert it into a map.