The query will return tuples of object (more detail in hibernate docs). Each tuple is an array of objects containined the values of the selected fields in the order they appear in the select list.
e.g.
Code:
Query q = session.createQuery( "Select Employee.empid,Employee.surName,salary.empid from Employee Employee,salary salary Where salary.empid=Employee.empid" );
Iterator results = q.list().iterator;
while (results.hasNext() {
Object[] tuple = (Object[])results.next();
Long empid = (Long)tuple[0];
String surname = (String)tuple[1];
Integer salary = (Integer)[2];
}
Obviously the types must match the data returned in your case.
An elegant alternative to this is to create a specific bean to hold the properties you're requesting. You can instruct hibernate to create and populate the bean in the query. The query result is then a list of these beans.
e.g.
Query:
"Select new com.xx.EmployeeBasicInfo(Employee.empid, Employee.surName, salary.empid) from Employee Employee,salary salary Where salary.empid=Employee.empid
Bean:
Code:
public class EmployeeBasicInfo {
private Long employeeId;
private String surname;
private int salary;
public EmployeeBasicInfo(Long employeeId, String surname, int salary) {
super();
this.employeeId = employeeId;
this.surname = surname;
this.salary = salary;
}
public Long getEmployeeId() {
return employeeId;
}
public String getSurname() {
return surname;
}
public int getSalary() {
return salary;
}
}