From: James A. (JIRA) <no...@at...> - 2006-07-21 09:43:13
|
Parenthesis removal without honouring order in HQL query -------------------------------------------------------- Key: HHH-1929 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1929 Project: Hibernate3 Type: Bug Components: query-hql Versions: 3.1.3, 3.2.0.cr3 Environment: Hibernate 3.1.3 and Hibernate 3.2.0.cr3, MySQL 5.0.22 community edition, Tomcat 5.5.17, Eclipse 3.2, WTP 1.5.0.2 Reporter: James Andrews Priority: Critical Parenthesis in the where clause of a HQL query are being removed in the produced SQL query, modifying the results from those intended. The HQL used is as follows: select inv from Involvement inv left outer join inv.outcomes out where ( out.type.needsDate = true and out.dateFinished <= now() ) or ( out is null and inv.charge is not null ) or ( out.dateCreated = ( select max(out2.dateCreated) from Outcome out2 where out2.involvementId = inv.id ) and out.type.terminal = false ) group by inv.id And results in the following SQL: select involvemen0_.involvementId as involvem1_2_, involvemen0_.chargeId as chargeId2_, involvemen0_.personId as personId2_, involvemen0_.involvementTypeId as involvem4_2_ from incident.involvement involvemen0_ left outer join incident.outcome outcomes1_ on involvemen0_.involvementId=outcomes1_.involvementId, incident.outcometype outcometyp2_ where outcomes1_.typeId=outcometyp2_.typeId and ( outcometyp2_.needsDate=1 and outcomes1_.dateFinished<=now() or ( outcomes1_.outcomeId is null ) and ( involvemen0_.chargeId is not null ) or outcomes1_.dateCreated=( select max(outcome3_.dateCreated) from incident.outcome outcome3_ where outcome3_.involvementId=involvemen0_.involvementId ) and outcometyp2_.isTerminal=0 ) group by involvemen0_.involvementId The initial subgroup of the clause is fine, however the ".charge is not null" and ".isTerminal = false" clauses are being promoted out of their subgroups, causing them to filter all results, rather than just those tuples with related criteria. This seems similar to issue HHH-377 and HHH-284, although it is not related to MySQL's issues with operator precedence, as the generated where clause does not fulfil the intent of the HQL where clause for any precedence rules. -- 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 |