-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Using Filters with Criteria: JDBC param index out of range
PostPosted: Wed Nov 02, 2005 2:53 pm 
Newbie

Joined: Fri May 27, 2005 10:45 am
Posts: 6
Hi,

The problem below occurs with both Hibernate 3.0.5 and Hibernate 3.1 rc2.
I tested it with two different databases: Sybase and HSQL DB and the same problem occurs.
It seems that there is a problem when you use the Criteria API and when there is a filter enabled.
The problem is an invalid argument in JDBC call: parameter index out of range.

Here is the mapping file:

Code:
<hibernate-mapping package="test.hibernate.mapping">

    <class name="TransactionImpl" table="test_transaction" mutable="false">
        <id name="id" column="id" type="java.lang.Integer" >
            <generator class="hilo"/>
        </id>
        <property name="client" column="client" type="java.lang.String"/>
        <property name="account" column="account" type="java.lang.String"/>
        <property name="otherData" column="other_data" type="java.lang.String"/>
        <filter name="ClientFilter"           
            condition="client in (
                 select fd.entity_id from test_filterdata fd where
                 fd.username=':username' and fd.namespace='ClientNameSpace' and fd.entitygroup_id='Client')"/>                                 
    </class>

    <class name="FilterDataImpl" table="test_filterdata" mutable="false">
        <id name="id" column="id" type="java.lang.Long">
            <generator class="hilo"/>
        </id>
        <property name="username" column="username" type="java.lang.String" not-null="true" />
        <property name="namespace" column="namespace" type="java.lang.String" not-null="true" />
        <property name="entityGroupId" column="entitygroup_id" type="java.lang.String" not-null="true" />
        <property name="entityId" column="entity_id" type="java.lang.String" not-null="true" />       
    </class>
   
    <filter-def name="ClientFilter">
        <filter-param name="username" type="java.lang.String"/>
    </filter-def>
   
</hibernate-mapping>



Here is a test program:

Code:
Session session = getSession();
       
// enable filter
session.enableFilter("ClientFilter").setParameter("username", "user");

// use Criteria API to do a search
Collection result = session.createCriteria(TransactionImpl.class).list();
System.out.println("result size: " + result.size());



And here is the exception stack trace with Sybase:

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:2150)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
   at org.hibernate.loader.Loader.list(Loader.java:2021)
   at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1483)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
   at test.hibernate.HibernateFilterTest.test1(HibernateFilterTest.java:56)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   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:436)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.sql.SQLException: JZ0SB: Parameter index out of range: 1.
   at com.sybase.jdbc3.jdbc.ErrorMessage.raiseError(ErrorMessage.java:552)
   at com.sybase.jdbc3.jdbc.ParamManager.checkIndex(ParamManager.java:324)
   at com.sybase.jdbc3.jdbc.ParamManager.setParam(ParamManager.java:374)
   at com.sybase.jdbc3.jdbc.SybPreparedStatement.setParam(SybPreparedStatement.java:1191)
   at com.sybase.jdbc3.jdbc.SybPreparedStatement.setParam(SybPreparedStatement.java:1184)
   at com.sybase.jdbc3.jdbc.SybPreparedStatement.setString(SybPreparedStatement.java:288)
   at org.hibernate.type.StringType.set(StringType.java:26)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:85)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:63)
   at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
   at org.hibernate.loader.Loader.doQuery(Loader.java:661)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
   at org.hibernate.loader.Loader.doList(Loader.java:2147)
   ... 21 more


Code:
And same with HSQL in-memory database:

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:2150)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
   at org.hibernate.loader.Loader.list(Loader.java:2021)
   at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1483)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
   at test.hibernate.HibernateFilterTest.test1(HibernateFilterTest.java:61)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   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:436)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.sql.SQLException: Invalid argument in JDBC call: parameter index out of range: 1
   at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
   at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
   at org.hsqldb.jdbc.jdbcPreparedStatement.checkSetParameterIndex(Unknown Source)
   at org.hsqldb.jdbc.jdbcPreparedStatement.setParameter(Unknown Source)
   at org.hsqldb.jdbc.jdbcPreparedStatement.setString(Unknown Source)
   at org.hibernate.type.StringType.set(StringType.java:26)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:85)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:63)
   at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
   at org.hibernate.loader.Loader.doQuery(Loader.java:661)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
   at org.hibernate.loader.Loader.doList(Loader.java:2147)
   ... 21 more


Is it a bug ?
Any workaround ?
Thanks
Patrick


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 2:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Submit a runnable test case to JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 2:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
why the quoting around the filter parameter in the condition? Is that just a typo?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 3:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
oh, duh. I missed that.


(Sorry for wasting your time, Steve.)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 3:26 pm 
Newbie

Joined: Fri May 27, 2005 10:45 am
Posts: 6
OK guys, sorry about that. Removed the quotes in the filter condition around the username and it works... :-#

Thanks a lot for your answers
Patrick


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.