From: Max R. A. (JIRA) <no...@at...> - 2006-05-30 12:33:17
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1748?page=all ] Max Rydahl Andersen closed HHH-1748: ------------------------------------ Fix Version: 3.2.0 Resolution: Fixed verified, the formatter expected that quotes were paired. Fixed by simply not triggering the exception - thus formatting will stop at the point of the quote. Not optimal but at least it does not throw exceptions. > Setting a comment that contains a single quote on a query results in an unintuitive exception > ---------------------------------------------------------------------------------------------- > > Key: HHH-1748 > URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1748 > Project: Hibernate3 > Type: Bug > Components: query-hql > Versions: 3.1.3 > Environment: Hibernate 3.1.3 > Oracle 10i > Java 1.4.2_08 > Centos 4 > Reporter: Corey Puffalt > Fix For: 3.2.0 > > > I've been using the (relatively) new setComment() feature which I find very useful during development and testing. However, I've stumbled across an error when setting a comment that contains a single quote . > For example: > List parents = session.createQuery("...").setComment("get kitten's parents").list(); > results in the following exception: > Caused by: java.util.NoSuchElementException > at java.util.StringTokenizer.nextToken(StringTokenizer.java:259) > at org.hibernate.pretty.Formatter.format(Formatter.java:112) > at org.hibernate.jdbc.AbstractBatcher.format(AbstractBatcher.java:355) > at org.hibernate.jdbc.AbstractBatcher.log(AbstractBatcher.java:346) > at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:422) > at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:368) > at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:105) > at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561) > at org.hibernate.loader.Loader.doQuery(Loader.java:661) > at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) > at org.hibernate.loader.Loader.doList(Loader.java:2145) > at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029) > at org.hibernate.loader.Loader.list(Loader.java:2024) > at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375) > at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308) > at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153) > at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106) > at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79) > at mypkdg.MyClass.mymethod(MyClass.java:964) > To get this particular error you also have to have the hibernate.format_sql property set to true (as you might guess from examining this stacktrace closely). While I don't have a problem with single quotes being prohibited in a comment if they can't be escaped I *do* have a problem with the exception above as it doesn't tell me what's wrong... Looks like a bug in the parser to me... > Astute readers may ask what happens if I turn off sql formatting (hibernate.format_sql=false). In this case, I got an exception from the Oracle10i JDBC driver: > Caused by: java.sql.SQLException: ORA-00911: invalid character > at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) > at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331) > at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288) > at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743) > at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216) > at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799) > at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039) > at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839) > at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1132) > at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285) > at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329) > at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:211) > at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139) > at org.hibernate.loader.Loader.getResultSet(Loader.java:1669) > at org.hibernate.loader.Loader.doQuery(Loader.java:662) > at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) > at org.hibernate.loader.Loader.doList(Loader.java:2145) > ... 43 more > Note that you'll also have to have the hibernate.use_sql_comments property set to true to reproduce this one. > I guess there are two ways of fixing this problem: > a) Explicitly prohibit "bad" characters like the single quote in comments and throw an appropriate exception. > b) Handle single quotes properly in the org.hibernate.pretty.Formatter and also escape such characters (if possible) appropriately so they don't cause errors at the JDBC driver level. > I assume this problem also affects comments set on Criterias and native SQL though I haven't verified this. -- 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 |