0

我有如下共享的休眠映射

<class name="com.service.Employee" table="EMPLOYEE" lazy="true">
    <id name="empId" type="java.lang.String" column="emp_id" length="50">
        <generator class="assigned" />
    </id>
    <property name="name" column="name">
    <property name="mobNumber" column="mob_number">
    <list name="refNumber" table="REF_NUMBERS">  
        <key column="refId"></key>  
        <list-index column="type"></index>  
        <element column="ref_number" type="string"></element>  
    </list>  
</class>

如您所见,我有两个表 EMPLOYEE 和 REF_NUMBERS。EMPLOYEE 表有 POJO,但 REF_NUMBERS 只是映射表。现在我想根据我随身携带的参考号码列表来获取员工姓名。我不想要完整的 Employee 对象只是员工姓名和相应的参考号。我怎么能写HQL这个?有什么办法可以实现Projection吗?

4

1 回答 1

0
select e.name, rn from Employee e join refNumber rn where rn in (:refNumbers)

query.setParameter("refNumbers", refNumbers);

for (Object[] row : (List<Object[]>) query.list()) {
   String name = (String) row[0];
   String rn = (String) row[1];
}
于 2015-07-22T13:33:55.630 回答