querydsl: BooleanBuilder OR condition generate invalid query

Hi,

I have encounter the following problem:

QueryDSL version: 3.6.5 Using the following libraries: querydsl-core querydsl-jdo querydsl-apt

{
    System.out.println("=== Test AND ===");
    BooleanBuilder builder = new BooleanBuilder();
    for (Predicate predicate : predicates) {
        builder.and(predicate);
        System.out.println(builder.getValue());
    }
}

{
    System.out.println("=== Test OR ===");
    BooleanBuilder builder = new BooleanBuilder();
    for (Predicate predicate : predicates) {
        builder.or(predicate);
        System.out.println(builder.getValue());
    }
}

The 2 predicates that i have in the ArrayList of “predicates” is the following: a) contains(lower(investorAccount.name),pf791798) b) contains(lower(investorAccount.ownedByUser.name),123) || contains(lower(investorAccount.ownedByUser.firstName),123)

This generate the following result:

=== Test AND === contains(lower(investorAccount.name),pf791798) && (contains(lower(investorAccount.ownedByUser.name),123) || contains(lower(investorAccount.ownedByUser.firstName),123)) === Test OR === contains(lower(investorAccount.name),pf791798) || contains(lower(investorAccount.ownedByUser.name),123) || contains(lower(investorAccount.ownedByUser.firstName),123)

in “Test AND”, the query are generated correct as “a && (b)”. However in “Test OR” the query is generated as “a || b”, there are no bracket around predicate “b”. The expected result should be “a || (b)”

Please could you have a look into this. And if you think my understanding is incorrect, please also let me know.

Please also let me know if you would need me to provide with more information

Many thanks!!!

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

It is a valid issue. If i do where.(e1).or(e2.and(e3), it is generating like where e1 or e2 and e3 which is wrong. What we need is where e1 or (e2 and e3). Can this issue be re-opened or new ticket is required?

i join this issue, priority on parenthesis are not respected. This change the result of the query and is quite important bug. I don’t agree also with the issue #690 on too many parenthesis generation. Parenthesis have their importancy cause they give priorities on boolean expression. As the code is generated, too many parenthesis doesn’t annoy anyone