HQL Queries not keeping the precedence order defined by me

30 views
Skip to first unread message

cidico

unread,
Dec 1, 2011, 8:27:29 AM12/1/11
to nhu...@googlegroups.com
Hi,

I'm using HQL to build a query and I found that NHibernate is cutting off my precedente orders.

For example my query is this

"    from Wharehouse wh
                                left outer join wh.CoverageArea as ca
                                where :zipCode BETWEEN ca.StartCEP and (ca.StartCEP + (ca.EndCEP - ca.StartCEP))"

but when executed, the result sql is this:

select wharehouse0_.WharehouseId as Wharehou1_24_,
       wharehouse0_.Name         as Name24_,
       wharehouse0_.ErpCode      as ErpCode24_
from   Wharehouses wharehouse0_
       left outer join WharehouseCoverageArea coveragear1_
         on wharehouse0_.WharehouseId = coveragear1_.WharehouseId
where  91260010 /* @p0 */ between coveragear1_.StartCEP and coveragear1_.StartCEP + coveragear1_.EndCEP - coveragear1_.StartCEP;


I'm not saying that the sql query is wrong (the result is ok), but why the NH does not keep my "(" and ")" ?
It could lead me to troubles when doing math operations in complex queries.

Oskar Berggren

unread,
Dec 1, 2011, 8:57:54 AM12/1/11
to nhu...@googlegroups.com
2011/12/1 cidico <cid...@live.com>:

> Hi,
>
> I'm using HQL to build a query and I found that NHibernate is cutting off my
> precedente orders.
>


Hmm... Have you tried with an expression where the parentheses matter
for precedence? I'm not sure, but I'm thinking that the parentheses
are removed when the expression is parsed as an abstract syntax tree
(since precedence would be encoded in the tree structure), and then
put back in the SQL only for the cases where it matters.

/Oskar

cidico

unread,
Dec 1, 2011, 9:56:26 AM12/1/11
to nhu...@googlegroups.com

Thanks for the quick reply Oskar!

I can't remeber right now one query where it could lead to trouble, but, last year I was working on some taxes calculations (I'm in Brazil and taxes calculations here are f****** crazy...) and I had troubles with precedences, but I was working inside stored procedures.

Just to clarify I was not speaking about any bug, was just to clarify my question.
I just found strange the fact that NH was "changing" my query.

But if this is like you're saying, I don't need to worry about this!

Thanks!!
Reply all
Reply to author
Forward
0 new messages