开发者

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).开发者_如何学Go 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜