通过在 Hibernate 中包含原始数据类型元素的列表上应用 where 子句来获取数据
Fetch data by applying where clause on list which contains premitive data type elements in Hibernate
我有像下面共享的休眠映射
<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>
如您所见,我有两个 table 雇员和 REF_NUMBERS。 EMPLOYEE table 有 POJO,但 REF_NUMBERS 只是映射 table。现在我想根据我随身携带的参考编号列表获取员工姓名。我不想要完整的 Employee 对象,只需要员工姓名和相应的参考编号。我如何为此写 HQL
?有什么办法可以用Projection
实现吗?
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];
}
我有像下面共享的休眠映射
<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>
如您所见,我有两个 table 雇员和 REF_NUMBERS。 EMPLOYEE table 有 POJO,但 REF_NUMBERS 只是映射 table。现在我想根据我随身携带的参考编号列表获取员工姓名。我不想要完整的 Employee 对象,只需要员工姓名和相应的参考编号。我如何为此写 HQL
?有什么办法可以用Projection
实现吗?
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];
}