[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2647?page=c...
]
Nicolas De Cubber commented on HHH-2647:
----------------------------------------
Hi again,
I made an error on the refactoring, here is the correct code:
The request :
(1 and 2) or (3 and 4) or (5 and 6)
can be rewrited like that :
NOT(NOT(1 and 2) AND NOT(3 and 4) AND NOT (5 and 6) )
If I took the example given by Dennis Fleurbaaij , the request:
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 )
)
will become :
FROM Entity
WHERE NOT
( NOT( entity.fromDateTime is null AND entity.toDateTime < :dateTime)
AND NOT
( entity.fromDateTime >= :dateTime AND entity.toDateTime is null )
AND NOT
( entity.fromDateTime >= :dateTime AND entity.toDateTime < :dateTime )
)
Anyway, i hope there will be a bug fix soon, because this workaround make queries less
readable.
[ Show ยป ] Nicolas De Cubber - [28/Aug/07 09:10 AM ] Hi, I had the same problem and it is
very annoying. Anyway, i found a work around. Apparently the parser for the request remove
all parenthesis and replace them when he think they are necessary. Unfortunately, it seems
that in the query builder they forgot to put parenthesis surrounding an OR condition. But,
hopefuly, the query builder put parenthesis for a NOT condition. Then the request : (1 and
2) or (3 and 4) or (5 and 6) can be rewrited like that : (1 and 2) AND NOT(~3 or ~4) AND
NOT (~5 or ~6) where ~3 is the opposite condition of 3 If I took the example given by
Dennis Fleurbaaij , the request: 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 ) ) will become : FROM Entity WHERE ( (
entity.fromDateTime is null AND entity.toDateTime < :dateTime) AND NOT (
entity.fromDateTime < :dateTime OR entity.toDateTime is not null ) AND NOT (
entity.fromDateTime < :dateTime AND entity.toDateTime >= :dateTime ) ) Anyway, i
hope there will be a bug fix soon, because this workaround make queries less readable.
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira