Tuesday, July 13, 2010

Hibernate : Get list of hash maps from org.hibernate.Query

We all know about the Hibernate Query Object (org.hibernate.Query) , If you want to execute a named sql query using Query object and you want it to return you the result as list of hash maps you can call following method

query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);

and then following line can give you the list of hash maps where each hash map has a key as the field name in your query and value is the value of that field in database.

List<map<string,object>> = query.list;