0

I have hibernate mapping like shared bellow

<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>

As you can see,I have two tables EMPLOYEE and REF_NUMBERS. There is POJO for EMPLOYEE table but REF_NUMBERS is just mapping table. Now I want to fetch employee name on the basis of list of reference numbers which I have with me. I don't want full Employee object just employee name and corresponding reference number. How I can write HQL for this? Is there any way to achieve with Projection?

1 Answer 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];
}
2
  • Will check and let you know
    – Navnath
    Jul 22, 2015 at 14:08
  • Can you provide some context to your answer, that way future readers can learn how to apply it to their issues and not just in this situation.
    – Newd
    Jul 22, 2015 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.