From: <leg...@at...> - 2003-08-28 13:48:33
|
The following comment has been added to this issue: Author: Roberto S. Tyley Created: Thu, 28 Aug 2003 8:46 AM Body: Sorry, I should have added in the environment section that the stack trace is actually from Hibernate 2.1beta2 - although the code still fails on all the other mentioned versions of Hibernate! --------------------------------------------------------------------- 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: Unassigned Priority: Major Project: Hibernate2 Components: core Versions: 2.0.1 2.0.2 2.1 beta 1 2.1 beta 2 Assignee: Reporter: Roberto S. Tyley Created: Thu, 28 Aug 2003 8:39 AM Updated: Thu, 28 Aug 2003 8:39 AM 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 |
From: <leg...@at...> - 2003-08-28 16:29:30
|
The following comment has been added to this issue: Author: Roberto S. Tyley Created: Thu, 28 Aug 2003 11:28 AM Body: Having had a look through the HB 2.1beta2 sources, I've found the apparent reason for this behaviour. The job of converting named parameters is being handled correctly by net.sf.hibernate.hql.WhereParser, while net.sf.hibernate.hql.OrderByParser is not performing this binding step. 'WhereParser' is substantially more complicated than 'OrderByParser' (465 lines vs 46!), but the code critical to this bug seems to be only 5 lines long, some code in the doToken() method at line 365 in WhereParser.java would do the job if pasted into the token() method around line 30 in OrderByParser.java. The code in WhereParser is: --------------- if ( q.isName( StringHelper.root(token) ) ) { //path expression doPathExpression( q.unalias(token), q); } else if ( token.startsWith(ParserHelper.HQL_VARIABLE_PREFIX) ) { //named query parameter q.addNamedParameter( token.substring(1) ); appendToken(q, "?"); } else { ... lalalala, lots of code here ... --------------- The code in OrderByParser is currently: ------------------ if ( q.isName( StringHelper.root(token) ) ) { ParserHelper.parse(pathExpressionParser, q.unalias(token), ParserHelper.PATH_SEPARATORS, q); q.appendOrderByToken( pathExpressionParser.getWhereColumn() ); pathExpressionParser.addAssociation(q); } else { q.appendOrderByToken(token); } ------------------- You can see that both pieces of code do the 'isName' test, but then OrderBy omits to do the test to see if the token starts with ParserHelper.HQL_VARIABLE_PREFIX (which has the value ':', of course!). Adding that test and the appropriate code to OrderByParser would fix my problem, though some kind of refactoring of WhereParser, OrderByParser, and the other Parser classes so that they can use common code might be a better solution . Incidentally, the hibernate source code can be a bit confusing regarding this issue. There are several variables and methods in net.sf.hibernate.impl.AbstractQueryImpl which might appear to do this job of named parameter binding, but which in fact do nothing at all unless you've used the setParameterList() method on Query - that is to say, you're binding lists of values, and not single values using methods like setDouble(), as I do in my example. 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: Unassigned Priority: Major Project: Hibernate2 Components: core Versions: 2.0.1 2.0.2 2.1 beta 1 2.1 beta 2 Assignee: Reporter: Roberto S. Tyley Created: Thu, 28 Aug 2003 8:39 AM Updated: Thu, 28 Aug 2003 8:39 AM 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 |
From: <leg...@at...> - 2003-08-28 19:37:30
|
The following comment has been added to this issue: Author: Gavin King Created: Thu, 28 Aug 2003 2:36 PM Body: Thanks for tracking this down. I'm not sure if its quite a "bug", since obviously noone ever tried to implement support for parameters in the ORDER BY clause. :) Still, we will make this change. --------------------------------------------------------------------- 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: Unassigned Priority: Major Project: Hibernate2 Components: core Versions: 2.0.1 2.0.2 2.1 beta 1 2.1 beta 2 Assignee: Reporter: Roberto S. Tyley Created: Thu, 28 Aug 2003 8:39 AM Updated: Thu, 28 Aug 2003 8:39 AM 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 |
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 |
From: <leg...@at...> - 2003-08-29 08:49:27
|
The following comment has been added to this issue: Author: Max Rydahl Andersen Created: Fri, 29 Aug 2003 3:48 AM Body: Please provide a patch and optimally a small test case for it! (Then I can probably add it) --------------------------------------------------------------------- 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 |