-
Notifications
You must be signed in to change notification settings - Fork 378
Description
Hello,
I am having some trouble when generating queries with the Criteria class (org.springframework.data.relational.core.query)
It's seems not possible to make a query like : (a OR b) AND c => This will be generated as a OR b AND c : it's not the same result.
I have defined the following method to generate an OR's combination :
private <T> Criteria createCriteria(
final Class<T> entityClass,
final BDFilterOr filter) {
// Critères de chaque opérande
return filter.getChildren()
.stream()
.map(child -> createCriteria(entityClass, child))
.reduce(Criteria::or)
.orElseThrow(() -> new MmiBadRequestException("Pas d'opérande généré pour le filtre OR"));
}
And for the AND combination :
private <T> Criteria createCriteria(
final Class<T> entityClass,
final BDFilterAnd filter) {
// Critères de chaque opérande
return filter.getChildren()
.stream()
.map(child -> createCriteria(entityClass, child))
.reduce(Criteria::and)
.orElseThrow(() -> new MmiBadRequestException("Pas d'opérande généré pour le filtre AND"));
}Doing this, I'm expecting to have an OR combination inside a AND combination rounded with parenthesis in the generated query. It's not the case, when the OR combination is the first operand of the AND combination.
To solve the problem, I have to ensure the OR sub criteria is not placed at the first position of a AND criteria : it can't be used in a generic engine...
Is this API still maintained ?
Is there any workaround to permit the use of this API in any OR / AND combination ?
Thank you.