我在hibernate映射文件中编写了一个命名sql查询,它只返回来自不同表的几列。
<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>
当我调用这个查询时。
final Query query = session.getNamedQuery("getEmployeeDetails");
final List<Object[]> list = (List<Object[]>) query.list();
返回对象数组的列表。是否有任何方法可以将此结果集作为Map的列表,以columnName作为键,并将其值作为value .
Query query=session.createSQLQuery(query);
query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);
List<Map<String,Object>> aliasToValueMapList=query.list();