1

I've got two entities: Category and Product with one-to-many relation.

How can I order categories by number of their products, with price greater than 100? Something like (this doesn't work):

query.from(category).leftJoin(category.products,
    product).orderBy(product.price.gt(100).count().desc()).list(category)
K139
  • 3,654
  • 13
  • 17
Maniek Stasz
  • 347
  • 3
  • 13
  • Possibly related? Might help you. http://stackoverflow.com/questions/20090098/how-do-you-specify-multi-column-orderspecifier-for-use-in-springdata-and-queryds – Josef E. May 04 '15 at 17:59

1 Answers1

2

Have you tried something like

query.from(category).leftJoin(category.products, product).where(product.price.gt(100)).
groupBy(category).orderBy(product.count().desc()).list(category);

I tried a variation of this on my current dataset and it produced reasonable results.

Michael Tontchev
  • 909
  • 8
  • 23