2

I wrote a named sql query in hibernate mapping file which return only few columns from different tables.

  <resultset name="employeeDetails">
     <return-scalar type="timestamp" column="joinDate"/>
     <return-scalar type="string" column="name"/>
     <return-scalar type="string" column="department"/>
     <return-scalar type="big_decimal" column="salary"/>
  </resultset>

  <sql-query name="getEmployeeDetails" resultset-ref="employeeDetails">
   <![CDATA[
    select ei.joinDate as joinDate, e.name as name, e.depatrment as department, e.salary as salary from Employee as e, Employee_Info as ei where ei.emp_id = e.id
    ]]>
  </sql-query>

When I called this query.

   final Query query = session.getNamedQuery("getEmployeeDetails");
   final List<Object[]> list = (List<Object[]>) query.list();

It returns List of Object Array. Is there any way to get this result set as List of Map with columnName as key and it value as Value.

krishna_5c3
  • 509
  • 6
  • 14

1 Answers1

4
Query query=session.createSQLQuery(query); 
query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); 
List<Map<String,Object>> aliasToValueMapList=query.list(); 
Cassian
  • 3,648
  • 1
  • 29
  • 40