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>