简体   繁体   中英

Hibernate Criteria API orderBy and Embedded element

Lets say I have a Report entity. Inside it there is @Embeddable ReportPeriod which has Integer month and Integer year fields. When i try to sort my Report report by its ReportPeriod reportPeriod it sorts report by month and year . How to change the order of sort ( year and then month ). Can this be solved by any of the annotations?

I guess you want to load several reports by hibernate criteria and sort them by its embebedded month and year?

Criteria crit = session.createCriteria(Report.class);
crit.addOrder(Order.asc("reportPeriod.year"));
crit.addOrder(Order.asc("reportPeriod.month"));
...=crit.list();

But I am not 100% sure if Order can be applied to an @Embeddable, but is expect it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM