Did quite research on this forum for a solution, but failed to find any clue how to do it. Forgive me if it is a repeated or stupid question.
I need to do QBE to find records of class Contact which has two properties defined as:
Code:
<property name="contactDate" column="CONTACT_DATE"
type="date" not-null="true"/>
<many-to-one name="employee" column="EMPLOYEE"
class="Employee" lazy="false"/>
"employee" is actually a one-to-one relationship.
Employee are stored in
another table. Employee has a property called
name.
I can retrieve and display Contact records together associated
Employee records in a single call to crit.list() (crit is a Criteria object)
I want to do sorting. I can sort on non-reference property contactDate
correctly.
However I dont know how to sort on Employee.name.The following is my code to get Contact and Employee records. "example"
is a Contact object.
Code:
Example target = Example.create(example).enableLike(MatchMode.ANYWHERE);
Criteria crit0 = getSession().createCriteria(Contact.class).add(target);
crit0.createCriteria("employee").add(Example.create(example.getEmployee()).enableLike(MatchMode.ANYWHERE));
crit0.addOrder(Order.asc("contactDate"));
List list = crit0.list();
Thanks for reading and thanks for your input!