I have two objects.
@Entity
class Person extends Model {
...
@OneToOne
Category category;
}
@Entity
class Category extends Model {
...
}
I need to get the 5 most used categories. How can I do that ?
Thanks,
EDIT : Solution
List<Object[]> c = Category.find(
"SELECT p.categorie, count(p.id) FROM Person p " +
"GROUP BY p.category ORDER BY count(p.category) DESC").fetch(2);
Your JPQL query would be something like this:
And you’d do query.setMaxResults(5) also.