[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2647) Problems with OR parenthesis in HQL

Nicolas De Cubber (JIRA) noreply at atlassian.com
Mon Oct 15 03:32:40 EDT 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2647?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_28425 ] 

Nicolas De Cubber commented on HHH-2647:
----------------------------------------

@Stephane
I agree with you that (A OR B) AND C is not the same as A OR B AND C, but the problem given by Dennis, is not with an 'OR' operator in parenthesis, but with an 'AND' operator. So if you have a version of Hibernate which transform your query '(A OR B) AND C' in 'A OR B AND C', it is clearly a bug.

@Denis
Hibernate does not make a copy of  SQL code into HQL code, there is a transformation. In fact, it seems there is a parser on the query, that make a Tree, and when visiting the tree, when it arrives at an 'AND' operator, it does not write the parenthesis.
If your problem is that it sometimes seems to move parenthesis, like in your example result 'and ( ( 1 ) and 2 or 3 and ( 4 ) or 5 and 6 )', it is easy to explain. Your request 1 and 4 are certainly of type 'IS NULL' or 'IS NOT NULL'.
If your problem is to find your query in your server log, you should use an other mechanism, like making your own log, because the conversion from HQL to SQL is not so straightforward.
In the example i had given by rewritting the query with 'NOT' operators, the SQL generated query, in my case, was not generated with 'NOT' operator, but seems much more to :
FROM Entity 
WHERE 
( ( entity.fromDateTime is null AND entity.toDateTime < :dateTime) 
  OR 
  ( entity.fromDateTime >= :dateTime AND entity.toDateTime is null ) 
  OR 
   ( entity.fromDateTime >= :dateTime AND entity.toDateTime < :dateTime ) 
) 
with parentehis placed (due to the fact that we had used a not operator).
And this reconversion is good because it reduces the number or operation to do, so it improves performance.

Finally, if it is a feature and not a bug, you should have created it has a 'New Feature' type and not with the 'bug' type



> Problems with OR parenthesis in HQL
> -----------------------------------
>
>                 Key: HHH-2647
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2647
>             Project: Hibernate3
>          Issue Type: Bug
>          Components: query-hql
>    Affects Versions: 3.2.1
>         Environment: Hibernate 3.2.1, postgresql 8.2, jboss 5 embedded beta 2
>            Reporter: Dennis Fleurbaaij
>   Original Estimate: 15 minutes
>  Remaining Estimate: 15 minutes
>
> Given the following (part) of a query in HQL (where 1 to 6 are comparisons of different types (=, <=, is null), but irrelevant for the problem posted here ):
> AND ( ( 1 AND 2 ) OR ( 3 AND 4 )  OR ( 5 AND 6 ) )
> will be balanced to:
> and ( ( 1 ) and 2 or 3 and ( 4 ) or 5 and 6 )

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list