From: John H. (JIRA) <no...@at...> - 2006-06-14 16:44:43
|
Wrong SQL generated for hql query on "any" relation --------------------------------------------------- Key: HHH-1838 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1838 Project: Hibernate3 Type: Bug Components: query-hql Versions: 3.2.0.alpha2, 3.1.3 Environment: Hibernate 3, PostgreSQL 8.0.3 Reporter: John Hughes Priority: Blocker Attachments: bug.jar Very easy to reproduce; an hql query like this: HibernateUtil.currentSession() .createQuery("from Container c where c.interf.class = 'Implementer'\ and interf = :i") .setParameter("i", interf) .list().iterator(); on a mapping like this: <hibernate-mapping default-access="field"> <class name="Container" table="Container"> <id name="hibernateId" column="container_id"> <generator class="native"/> </id> <any name="interf" meta-type="string" id-type="long"> <column name="interf_type"/> <column name="interf_id"/> </any> </class> </hibernate-mapping> produces an error like this: 12:34:21,335 INFO LongType:91 - could not bind value '16' to parameter: 2; The\ column index is out of range: 2, number of columns: 1. 12:34:21,349 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: 22023 12:34:21,353 ERROR JDBCExceptionReporter:72 - The column index is out of range:\ 2, number of columns: 1. Exception in thread "main" org.hibernate.exception.DataException: could not exe\ cute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.\ java:77) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHel\ per.java:43) at org.hibernate.loader.Loader.doList(Loader.java:2148) 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:392) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.j\ ava:333) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.jav\ a:172) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1123) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79) at Test.create(Test.java:41) at Test.main(Test.java:11) Caused by: org.postgresql.util.PSQLException: The column index is out of range\ : 2, number of columns: 1. at org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.\ java:38) at org.postgresql.core.v3.SimpleParameterList.setLiteralParameter(Simpl\ eParameterList.java:68) at org.postgresql.jdbc2.AbstractJdbc2Statement.bindLiteral(AbstractJdbc\ 2Statement.java:2046) at org.postgresql.jdbc2.AbstractJdbc2Statement.setLong(AbstractJdbc2Sta\ tement.java:1088) at org.hibernate.type.LongType.set(LongType.java:42) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65) at org.hibernate.type.AnyType.nullSafeSet(AnyType.java:139) at org.hibernate.type.AnyType.nullSafeSet(AnyType.java:117) at org.hibernate.loader.hql.QueryLoader.bindNamedParameters(QueryLoader\ .java:515) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1577) at org.hibernate.loader.Loader.doQuery(Loader.java:661) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(L\ oader.java:224) at org.hibernate.loader.Loader.doList(Loader.java:2145) ... 9 more The generated SQL is this: select container0_.container_id as container1_0_, container0_.interf_type as interf2_0_, container0_.interf_id as interf3_0_ from Container container0_ where container0_.interf_type='Implementer' and (container0_.interf_type, container0_.interf_id)=? I'm attaching a small jar file which reproduces the error. -- 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 |