|
Copy paste errors all over in the previous comment, this is better: @Entity With the following HQL code: FROM Entity I am getting the same problem: "c.owner=? and (" HQL snipped is getting converted to: select contact0_.ym_contact_id as ym1_25_, contact0_.title as title25_, contact0_.firstName as firstName25_, contact0_.middleName as middleName25_, contact0_.lastName as lastName25_, Hi, I had the same problem and it is very annoying. Anyway, i found a work around. Then the request : where ~3 is the opposite condition of 3 If I took the example given by Dennis Fleurbaaij , the request: will become : Anyway, i hope there will be a bug fix soon, because this workaround make queries less readable. Hi again, I made an error on the refactoring, here is the correct code: The request : If I took the example given by Dennis Fleurbaaij , the request: will become : Anyway, i hope there will be a bug fix soon, because this workaround make queries less readable. Nicolas, Great find! It fixes the problem in the short run and will not break when Hibernate is patched. The perfect workaround. Dennis I was still looking at that problem, and finally, i found it was not a problem. It is like in Mathematics where the multiplication has priority over the addition. So, this bug (which is not a bug) can be close because it was a misunderstood of the sql language. see SQL condition Precedence here : http://download-uk.oracle.com/docs/cd/B14117_01/server.101/b10759/conditions001.htm#i1034741 @Nicolas: I disagree with you. While you are right that precedence does work in this case, the brackets are misaligned from the HQL to the SQL and that certainly is a bug. Furthermore the feature (it's not a bug it's a feature!) of being able to arbitrarily place brackets is very handy and much used. That alone should be reason enough to have it. Stripping out the bracket possibility as a feature and declaring the bug therefore nonexistent because the feature is not supported is not the way to go IMHO. I have the same problem in my application, and I think that is is exactly the same bug as @Nicolas This is a bug. @Stephane @Denis 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 @Nicolas In despite of the fact that this is some obscure undocumented* behaviour and that a natural feeling of parenthesis, as used in math/normal SQL/programming languages is concidered a feature requested, I still think it's a bug. Bugs aren't only against erronous code, but also against things like these. Performance improvements are something to watch out for, I do agree with you on that, but the loss in developer time and increase in complexity/non standards conformity (see how long this topic is opened) far outwheighs any small optimizations in the query IMHO.
Dear all, I think I encountered the same problem. Will there be a fix for this ? or is there any workaround ? HQL query : select o from VwPubQaAnswer o SQL generated: select vwpubqaans0_.QA_ID as QA1_1652_, vwpubqaans0_.ANSWER as ANSWER1652_, vwpubqaans0_.ARTICLE_ID as ARTICLE3_1652_, vwpubqaans0_.CREATED_DATE as CREATED4_1652_, vwpubqaans0_.PARENT_ARTICLE_ID as PARENT5_1652_, vwpubqaans0_.QUESTION as QUESTION1652_, vwpubqaans0_.REPLIED_DATE as REPLIED7_1652_, vwpubqaans0_.REPLIED_DISPLAY_NAME as REPLIED8_1652_, vwpubqaans0_.SENDER_NICKNAME as SENDER9_1652_ Thanks. Please attach a runnable test case (Java + mapping). I tried changing the query by using the NOT and AND variation. But doesn't look like it's resolving the issue. The hibernate generated SQL output from console: Thanks I do not see the problem. and which the where condition can be write has follow : but, because '.' has prioritary on '+', you could also write it like : I'm getting the same problem with the following and Nicolas's workaround to use NOT(not(3 and 4) and not(5 and 6) doesnt work. HQL: from SymbolMappingImpl e SQL: select symbolmapp0_.SymbolMappingId as SymbolMa1_217_, symbolmapp0_.SubBusinessDivisionCdId as SubBusin2_217_, I attached XML and java file. I have to fallback to raw SQL query to solve that one.... apologies, after doing more testing it does appear that the results are consistent however I think that HQL should not tamper with parenthesis put there on purpose by the developer, it is only confusing and time consuming for the developer to figure things out. Thanks, Any news regarding this issue? Regards, The first phase of the query parser actually groups and aligns the predicates according to your parenthesis; it changes the order in which they are evaluated (imagine, just like would happen in the sql's query translator!). @Guillaume, @Denis Would it be ideal to be able to match the parenthesis from the input string into the output string. Well perhaps (I personally think it is not necessary since as y'all are finding out the results are consistent). However, this will not happen unless someone steps up and produces a patch for this. It is extremely difficult to do and you get zero benefit for all that effort. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Just some code to get you started.
@Entity
{ private Date dateTime; }public Class Entity
With the following HQL code:
FROM Entity
WHERE
( ( entity.dateTime is null AND entity.toDateTime < :dateTime)
OR
( entity.dateTime >= :dateTime AND entity.toDateTime is null )
OR
( entity.dateTime >= :dateTime AND entity.toDateTime < :dateTime )
)