Hi
c.addOrder( Order.desc("contactinfo")) // this will work 100%
c.addOrder( Order.desc("contactinfo.name")) // this will not work 100%.
reason is very simple.
property NAME is not the joining key or foreign key.
you can just order by foriegn key properties.
like contactinfor.employeeId
your mapping file will not be joining with the ContactInfo mapping file on Name property.
you can only order by those properties which are there in the mapping file.
for example:
here is my employee mapping file.
<class name="EmployeeDTO" mutable="false" table="DB2.WRKFRC_CRNT2_VW">
<id name="empId" column="WRKFRC_ID">
<generator class="native" />
</id>
<property name="emailId" column="EML_ADDR_TXT" />
<property name="empName" formula=" concat( RTRIM(PRMY_LAST_NM), concat(', ',RTRIM(PRMY_FRST_NM)))" />
<property name="formalLdrId" column="FORMAL_LDR_ID" />
<property name="empFullNameWithMiddleInitial"
formula="concat( RTRIM(PRMY_LAST_NM), CONCAT(' ',CONCAT(RTRIM(PRMY_FRST_NM),concat(' ',RTRIM(PRMY_MID_NM)))))" />
<many-to-one name="department" class="DepartmentDTO" column="DEPT_ID" update="false" insert="false" lazy="false" />
<many-to-one name="manager" class="ManagerDTO" column="FORMAL_LDR_ID" update="false" insert="false" lazy="false" />
<one-to-one class="AddressDTO" name="address" foreign-key="TAX_ID"></one-to-one>
<join table="DB2.RAMS_WRKFRC_DTL_VW">
<key column="WRKFRC_ID" />
<property name="userId" column="USER_ID" />
</join>
</class>
Code:
Criteria crt = session.createCriteria(EmployeeDTO.class);
now, order by Department.id will work.
but order by Department.Name will not work.
order by AddressDTO will work,
order by AddressDTO.id will work
but order by AddressDTO.zipCode will not work.
thanks,
Abid,
you can mail me for further clarifications.