2011-01-21 32 views
0

可以說我有一個Report實體。裏面有@Embeddable ReportPeriod其中有Integer monthInteger year字段。當我嘗試通過其ReportPeriod reportPeriod對我的Report report進行分類時,它按monthyear分類report。如何更改排序順序(year,然後month)。這可以通過任何註釋解決嗎?休眠標準API orderBy和嵌入式元素

+0

請讓你的問題更清楚:你想什麼時候排序,以及如何? - 通過Criteria Api Query或Collections.sort? – Ralph 2011-01-21 15:18:02

回答

1

我想你想通過休眠標準加載幾個報告,並按其嵌入的月份和年份進行排序?

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

但我不是100%確定訂單是否可以應用於@Embeddable,但期望它。