Hi,
I'm using Querydsl 3.2.2. with Hibernate 4.2.4 and MySQL and playing with several logical expressions combined with AND / OR operators.
I'm wondering why BooleanExpression.orAllOf() outputs parentheses and BooleanExpression.andAnyOf() does not.
For example:
JPAQuery = ...
QAccountEntity account = ...
query.where(account.name.isNotNull().andAnyOf(account.name.eq("alpha"), account.name.eq("beta")));
Generates the following JPQL snippet (as expected):
where a.name is not null and (a.name = ?1 or a.name = ?2)
But if I write
JPAQuery = ...
QAccountEntity account = ...
query.where(account.name.isNotNull().orAllOf(account.name.eq("alpha"), account.name.eq("beta")));
I have:
where a.name is not null or a.name = ?1 and a.name = ?2
I guess the answer is operator precedence in JPQL (OR has lower precedence than AND), but IMHO I find it error prone: 1) when reading it (debugging purposes) and 2) hibernate does not seem to respect the operator precedence.
Is there a way to force use of parentheses or is it something you might consider adding?
--
Thanks a lot.
Frans
You received this message because you are subscribed to the Google Groups "Querydsl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to querydsl+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Hi.
On Tue, Aug 27, 2013 at 6:14 PM, Frans via Querydsl <querydsl+noreply-APn2wQe26Ka2Q9tImJZ8NkTb1mX8KUHVTNI0z2rlQDYm1dH@googlegroups.com> wrote:
Hi,
I'm using Querydsl 3.2.2. with Hibernate 4.2.4 and MySQL and playing with several logical expressions combined with AND / OR operators.
I'm wondering why BooleanExpression.orAllOf() outputs parentheses and BooleanExpression.andAnyOf() does not.
For example:
JPAQuery = ...
QAccountEntity account = ...
query.where(account.name.isNotNull().andAnyOf(account.name.eq("alpha"), account.name.eq("beta")));
Generates the following JPQL snippet (as expected):
where a.name is not null and (a.name = ?1 or a.name = ?2)
But if I write
JPAQuery = ...
QAccountEntity account = ...
query.where(account.name.isNotNull().orAllOf(account.name.eq("alpha"), account.name.eq("beta")));
I have:
where a.name is not null or a.name = ?1 and a.name = ?2
I guess the answer is operator precedence in JPQL (OR has lower precedence than AND), but IMHO I find it error prone: 1) when reading it (debugging purposes) and 2) hibernate does not seem to respect the operator precedence.
I find it more readable with minimal unnecessary parentheses.
How does Hibernate not respect operator precedence? As far as I know and/or precedence is the same for JPQL and many SQL dialects.