0

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?

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
Sebastian
  • 1
  • 1
  • Please make you question more clear: When do you want to sort, and how? - By an Criteria Api Query, or by Collections.sort? – Ralph Jan 21 '11 at 15:18

1 Answers1

1

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.

Ralph
  • 118,862
  • 56
  • 287
  • 383