Employee have employee related information including EmpID.
Site have Site related information including site id and site name.
Employee_Site have EmpID and SiteID records.
So, here we have multiple SiteIDs for given EmpID.
Also, we have mapping files for 3 classes.
Employee class have "sites" attribute with type as Set
class Employee {
----
---
Set sites;
}
Employee hbm file has entry as below-
<set name="sites" table="Employee_Site">
<key column="EMP_ID" foreign-key="FK_EMPLOYEE_ID" />
<many-to-many column="SITE_ID" class="Site" foreign-key="FK_SITE_ID" />
</set>
Now, when employee gets loaded I wanted to have set of Site as sorted. Sorted by site name, that is stored in Site table.
And, I wanted to use order-by clause. Can anyone tell me how I can achieve this ?
This is how I can think of -
1. Site implements Comparator. Compare by site name.
2. Association - Emp -> TreeSet<Sites>
3. Overide Intercepor -> onLoad() for emp, Use criteria with order by clause to load sites