0

I use Hibernate with MS SQL. Suppose I have a Car with a lot of associations, one of them being and Owner. Suppose I am interested some subset of the Cars:

getSession().createCriteria(Car.class)
  .createAlias("m_owner", "owner")
  .add(Restrictions.eq("m_color", "Blue")
  // a lot more restrictions on Car and its associations
  .addOrder(Order.asc("owner.m_lastName").ignoreCase())
  .list()

I want to limit the results to 25 owners, but an owner can have multiple cars.

Is it possible to specify an offset and a limit (of 25) in the above, such that the result set contains at most 25 distinct owners?

Jos
  • 1,015
  • 2
  • 13
  • 25
  • May it helps you http://stackoverflow.com/questions/300491/how-to-get-distinct-results-in-hibernate-with-joins-and-row-based-limiting-pagi – Vladlen Gladis Oct 20 '16 at 06:37
  • Thanks. An extra query is an option, but that would mean a lot of repeating of the restrictions on associations (example above is off course simplified). I wonder if there is a way to prevent that. – Jos Oct 20 '16 at 06:49

0 Answers0