-->
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.  [ 2 posts ] 
Author Message
 Post subject: Sql Server Stored Procedure fails with Index error
PostPosted: Wed Nov 02, 2005 4:45 pm 
Newbie

Joined: Fri Jun 04, 2004 4:21 pm
Posts: 3
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 11:42 am 
Newbie

Joined: Fri Jun 04, 2004 4:21 pm
Posts: 3
Well, finally found the examples under "test\org\hibernate\test\sql\" and modelled my trivial implemenation after the paramhandling example and got it working, at least enough to return a scalar. Now I just have to figure out how to get the mapping to happen a la: http://www.hibernate.org/hib_docs/v3/re ... /#sp_query

Suggestions welcomed.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.