I'm actually creating research with different filters.
As I'm using the JpaRepository to make simple queries, I found the JpaSpecificationExecutor to make dynamic queries with the Criterias.
My problem is I need to create a complex query with a group by and a count(). It's ok for the group by but I don't find how I can overide the "select" part to put a "count" instruction.
Does anybody can help me please ?
I'm using spring 3.1.2 and spring-jpa-data 1.0.3 Here is my code :
return new Specification< Article >() {
@Override
public Predicate toPredicate(final Root<Article> root,
final CriteriaQuery<?> query, final CriteriaBuilder builder) {
//count ???
query.groupBy(root.get(Article_.id));
Predicate p = builder.and(builder.like(root.<String> get(Article_.title), "%" + title + "%"));
return p;
}
}
Thanks !