You can choose how you select your properties
http://docs.jboss.org/hibernate/stable/core/reference/en/html/queryhql.html#queryhql-selectI would do something like
Code:
Query q = session.createQuery("select e.firstName, e.lastName, d.departmentName from Employee e inner join employee.department as d");
Or, more readable:
select e.firstName, e.lastName, d.departmentName
from Employee e
inner join employee.department as d
I don't know whether the join in the where clause works in HQL. And especially, you should then be doing where e.department.id as department has a getId() method. Your employee shouldn't have a getDepartmentId() method but a getDepartment() method which returns a Department instance.
The more sophisticated way is returning a map of aliasses and select values, like this:
Code:
Query q = session.createQuery("select new map(e.firstName as firstName, e.lastName as lastName, d.departmentName as department) from Employee e inner join employee.department as d");
Or, more readable:
select new map(e.firstName as firstName, e.lastName as lastName, d.departmentName as department)
from Employee e
inner join employee.department as d
Or just do "from Employee" and do the necessary getters (if you do getDepartment() he will join automatically or execute a "select ... from department where department_id = ...." query with the department_id found in the employee.