Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
For the life of me, I can't figure out how to call a simple stored proc taking 1 parameter:
Hibernate version: version 3.1 rc2, Oct 07, 2005
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.wachovia.cmg.helios">
<class
name="Portfolios"
table="portfolios"
>
<id
name="Id"
type="java.lang.Integer"
column="id">
<generator class="identity" />
</id>
<property
name="Name"
column="name"
type="string"
not-null="true"
length="64"
/>
<property
name="Description"
column="description"
type="string"
not-null="true"
length="84"
/>
<property
name="Manager"
column="manager"
type="string"
not-null="false"
length="64"
/>
<property
name="PortfolioGroup"
column="portfolio_group"
type="string"
not-null="false"
length="64"
/>
<property
name="Benchmark"
column="benchmark"
type="string"
not-null="false"
length="64"
/>
</class>
<sql-query name="test_SP" callable="true">
<return alias="portfolio" class="Portfolios">
<return-property name="Name" column="name"/>
</return>
{ ? = call test_SP( :portfolioName) }
</sql-query>
</hibernate-mapping>
try {
Query query=q_session.getNamedQuery("test_SP");
query.setParameter("portfolioName","IDA");
List booking_ref=query.list();
} catch (Exception e) {
e.printStackTrace();
}
Caused by: java.sql.SQLException: Invalid Parameter index 0. JDBC indexes start at 1.
at net.sourceforge.jtds.jdbc.PreparedStatement_base.setParam(PreparedStatement_base.java:643)
at net.sourceforge.jtds.jdbc.CallableStatement_base.setParam(CallableStatement_base.java:239)
at net.sourceforge.jtds.jdbc.PreparedStatement_base.setString(PreparedStatement_base.java:790)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setString(WrappedPreparedStatement.java:406)
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.bindNamedParameters(Loader.java:1745)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1577)
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)
... 51 more
Name and version of the database you are using: SQL Server 2000
The generated SQL (show_sql=true): 15:40:49,163 INFO [STDOUT] Hibernate: { ? = call test_SP( ?) }
Debug level Hibernate log excerpt:
15:40:49,179 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null
15:40:49,179 ERROR [JDBCExceptionReporter] Invalid Parameter index 0. JDBC indexes start at 1.