We all know that one-to-many can be sorted by configuring a order-by= "* * desc"
Such as:
Code
<set name= "Clubmessage" table= "Club_message" inverse= "true" cascade= "delete" order-by= "Create_time desc" >
<key column= "club_id"/>
<one-to-many class= "Com.test.item.club.domain.ClubMessageVO"/>
</set>
The above HBM attribute means that a community corresponds to more than one community message, and the messages are sorted by Create_time
Import Java.util.Comparator;
Import My. User;
public class Gbcomparator implements comparator{
public int Compare (object O1, Object O2) {
if (O1 = = null) {
return O2 = null? 0:1;
}
if (O2 = = null) {
return-1;
}
if (O1 instanceof user && O2 instanceof user) {
return (user) O1. Getaccount (). CompareTo ((user) O2). Getaccount ());
}
return 0;
}
}
<set
Name= "Users"
Table= "User_group_rel"
Cascade= "None"
Inverse= "true"
Sort= "My. Gbcomparator ">
<key column= "grouping_id"/>
<many-to-many column= "user_id" class= "USER"/>
</set>