Hello,
I opened JPA_SPEC-44, which was closed
(
http://java.net/jira/browse/JPA_SPEC-44).
It was about the criteria query API missing a where() method with a List
parameter:
CriteriaQuery<T> where(List<Predicate> restrictions);
Although groupBy, having, orderBy etc. all have both array (varargs) and
List parameter versions.
The issue was closed with this comment:
"It was felt that CriteriaQuery<T> where(List<Predicate> restrictions)
was not needed, as unlike in the other cases, there are operations to
combine expressions using the logical operators."
However, I think it would be a good idea to include it. I'm using the
criteria API like this:
List<Predicate> predicates = new ArrayList<>();
ClientStatus searchedClientStatus = clientSearch.getClientStatus();
if (searchedClientStatus != null) {
Predicate clientStatusPredicate = ....;
predicates.add(clientStatusPredicate);
}
String searchedCity = clientSearch.getCity();
if (searchedCity != null) {
Predicate cityPredicate = ....;
predicates.add(cityPredicate);
}
I then have to do this:
Predicate[] predicateArray = predicates.toArray(new Predicate[0]);
clientQuery.where(predicateArray);
I think it would be easier, and the API would be more consistent, if we
could just do this:
clientQuery.where(predicates);
What do you think?
Best regards,
Yannick Majoros