From: <leg...@at...> - 2003-08-29 08:32:27
|
The following comment has been added to this issue: Author: Roberto S. Tyley Created: Fri, 29 Aug 2003 3:32 AM Body: Cool! :-) Once I patched my copy of HB2.1beta2 last night, the named parameters queries worked fine. My patch was just to add 5 lines to OrderByParser, so the token() method is now: public void token(String token, QueryTranslator q) throws QueryException { if ( q.isName( StringHelper.root(token) ) ) { ParserHelper.parse(pathExpressionParser, q.unalias(token), ParserHelper.PATH_SEPARATORS, q); q.appendOrderByToken( pathExpressionParser.getWhereColumn() ); pathExpressionParser.addAssociation(q); } else if ( token.startsWith(ParserHelper.HQL_VARIABLE_PREFIX) ) { //named query parameter q.addNamedParameter( token.substring(1) ); q.appendOrderByToken("?"); } else { q.appendOrderByToken(token); } } Cheers, Roberto --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-297 Here is an overview of the issue: --------------------------------------------------------------------- Key: HB-297 Summary: Named Parameters not recognized in 'order by' section of Query Type: Bug Status: Assigned Priority: Major Project: Hibernate2 Components: core Versions: 2.0.1 2.0.2 2.1 beta 1 2.1 beta 2 Assignee: Gavin King Reporter: Roberto S. Tyley Created: Thu, 28 Aug 2003 8:39 AM Updated: Thu, 28 Aug 2003 3:41 PM Environment: java.version=1.4.2 os.name=Windows 2000 Mckoi DB 1.0.2 Description: The following query using named parameters fails: Query q=session.createQuery("from Location loc where (loc.lonLat.UnitX between :minX and :maxX) order by ABS( loc.lonLat.UnitX - :centX )"); q.setDouble("minX", x - r); q.setDouble("maxX", x + r); q.setDouble("centX", x); Iterator locs = q.iterate(); // Fails with QueryException The final bit with 'centX' causes the problem, as the following query, with the 'centX' removed, succeeds: Query q=session.createQuery("from Location loc where (loc.lonLat.UnitX between :minX and :maxX) order by ABS( loc.lonLat.UnitX )"); q.setDouble("minX", x - r); q.setDouble("maxX", x + r); Iterator locs = q.iterate(); // Succeeds Also, using JDBC-style un-named parameters works: Query q=session.createQuery("from Location loc where (loc.lonLat.UnitX between ? and ?) order by ABS( loc.lonLat.UnitX - ? )"); q.setDouble(0, x - r); q.setDouble(1, x + r); q.setDouble(2, x); Iterator locs = q.iterate(); // Succeeds Both of these two succeeding queries bring back all the results I would expect, with the correct ordering - so none of the function-calls or presence of a parameter in the order-by clause should be illegal. The full stack trace is: net.sf.hibernate.QueryException: Named parameter does not appear in Query: centX [from com.thisbedisonfire.madgag.persistence.Location loc where (loc.lonLat.UnitX between :minX and :maxX) order by ABS( loc.lonLat.UnitX - :centX )] at net.sf.hibernate.hql.QueryTranslator.getNamedParameterLocs(QueryTranslator.java:437) at net.sf.hibernate.hql.QueryTranslator.bindNamedParameters(QueryTranslator.java:817) at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:575) at net.sf.hibernate.hql.QueryTranslator.iterate(QueryTranslator.java:832) at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1436) at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:29) at com.thisbedisonfire.madgag.Main.main(Main.java:105) So, something's going wrong with binding of named parameters... Hope you can help! Roberto S. Tyley --------------------------------------------------------------------- JIRA INFORMATION: 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 If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira |