Hibernate version:
3.1.2
Hi,
I just updated to from 3.0.5 to 3.1.2 and one of my HQL queries stoped working. The query looks like this:
Code:
String query = "FROM EntitySpecificationValue esv LEFT JOIN FETCH esv.attributes WHERE esv.identifier IN (:ids)";
List res = session.createQuery(query).setParameterList("ids", ids).list();
ids is a List of Long objects. This used to work in 3.0.5 but now I get the following exception:
Code:
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.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: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:1129)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.xxx.se.inventory.dao.EntitySpecificationDaoImpl.getEntitySpecificationsByIds(EntitySpecificationDaoImpl.java:169)
at com.xxx.se.inventory.dao.EntitySpecificationDaoImpl.getEntitySpecificationsByKeys(EntitySpecificationDaoImpl.java:149)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy1.getEntitySpecificationsByKeys(Unknown Source)
at com.xxx.se.inventory.dao.EntitySpecificationDaoTest.testGetSpecificationsByKeysAndRemove(EntitySpecificationDaoTest.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
Caused by: java.sql.SQLException: Missing IN or OUT parameter at index:: 1
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:1536)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2900)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2946)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
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)
... 36 more
The generated SQL is correct and looks like this:
Code:
select
entityspec0_.ID as ID104_,
entityspec0_.OPTIMISTIC_LOCKING_VERSION as OPTIMISTIC3_104_,
entityspec0_.KIND_ID as KIND4_104_,
entityspec0_.POLYMORPHIC_DISCRIMINATOR as POLYMORP2_104_,
attributes1_.SPEC_ID as SPEC1_0__,
attributes1_.NAME as NAME0__,
attributes1_.ATTR_VALUE as ATTR3_0__,
attributes1_.DISCRIMINATOR as DISCRIMI4_0__
from IPS_SPECIFICATION entityspec0_ left outer join IPS_SPECIFICATION_ATTRIBUTE attributes1_ on entityspec0_.ID=attributes1_.SPEC_ID where entityspec0_.ID in (? , ?)
It works fine if I change my code to look like this:
Code:
String toString = ids.toString();
String params = toString.substring(1, toString.length()-1);
String query = "FROM EntitySpecificationValue esv LEFT JOIN FETCH esv.attributes WHERE esv.identifier IN (" + params + ")";
List res = session.createQuery(query).list();