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.  [ 1 post ] 
Author Message
 Post subject: Invalid Parameter index exception
PostPosted: Wed Jun 16, 2004 5:33 pm 
Newbie

Joined: Wed May 12, 2004 2:57 pm
Posts: 17
Hi all, I try to do a query like this

Code:
StringBuffer sb = new StringBuffer();
sb.append(SELECT_ALL);
sb.append(" where procedurecategory.procedure = ? AND procedurecategory.parentCategory IS NULL");
objs = session.find(sb.toString(), obj, Hibernate.OBJECT);


and I get a exception message that says:

Could not execute query
java.sql.SQLException: Invalid Parameter index 2. This statement only has 1 parameters

I change the query a little bit so that it compares id property instead of the whole Procedure object and it now works
Code:
StringBuffer sb = new StringBuffer();
sb.append(SELECT_ALL);
sb.append(" where procedurecategory.procedure.id = ? AND procedurecategory.parentCategory IS NULL");
objs = session.find(sb.toString(), obj.getId(), Hibernate.INTEGER);


Can someone tell me the reason behind this? Thank you.

Here are the mapping files
Code:

<class
        name="foo.Procedure"
        table="TBL_PROCEDURE"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="ID"
            type="java.lang.Integer"
        >
            <generator class="hilo">
            </generator>
        </id>

        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="NAME"
            length="50"
            not-null="true"
        />       

        <many-to-one
            name="procedureStatus"
            class="foo.ProcedureStatus"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
        >
            <column
                name="PROCEDURE_STATUS_ID"
            />
        </many-to-one>

        <set
            name="cases"
            lazy="true"
            inverse="true"
            cascade="none"
            sort="unsorted"
        >

              <key
                  column="PROCEDURE_ID"
              >
              </key>

              <one-to-many
                  class="foo.Case"
              />
        </set>

        <set
            name="procedureCategories"
            lazy="false"
            inverse="true"
            cascade="none"
            sort="unsorted"
        >

              <key
                  column="PROCEDURE_ID"
              >
              </key>

              <one-to-many
                  class="foo.ProcedureCategory"
              />
        </set>
    </class>


<class
        name="foo.ProcedureCategory"
        table="TBL_PROCEDURE_CATEGORY"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="ID"
            type="java.lang.Integer"
        >
            <generator class="hilo">
            </generator>
        </id>

        <many-to-one
            name="parentCategory"
            class="foo.ProcedureCategory"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
        >
            <column
                name="PARENT_CATEGORY_ID"
            />
        </many-to-one>

        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="NAME"
            length="50"
            not-null="true"
        />       

        <many-to-one
            name="procedure"
            class="foo.Procedure"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
        >
            <column
                name="PROCEDURE_ID"
            />
        </many-to-one>

        <set
            name="productSystems"
            table="TBL_PROCEDURE_CATEGORY_PRODUCT_SYSTEM"
            lazy="false"
            inverse="false"
            cascade="all"
            sort="unsorted"
        >

              <key
                  column="PROCEDURE_CATEGORY_ID"
              >
              </key>

              <many-to-many
                  class="foo.ProductSystem"
                  column="PRODUCT_SYSTEM_ID"
                  outer-join="auto"
               />

        </set>

        <set
            name="subCategories"
            lazy="false"
            inverse="false"
            cascade="all"
            sort="unsorted"
        >

              <key
                  column="PARENT_CATEGORY_ID"
              >
              </key>

              <one-to-many
                  class="foo.ProcedureCategory"
              />
        </set>

    </class>


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

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.