Hibernate Set Sort

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.