title: Hibernate, Stored Procedures and Invalid Parameter Index Error
body: <p>I have a SQL Server Stored Procedure that looks like this:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[my_stored_procedure] 
      (
          @num INT,
          @name VARCHAR(50),
          @start_date DATETIME,
          @end_date DATETIME
      )
  AS
  BEGIN
  ...
  END
  </code></pre>
  
  <p>And an Entity Object with a NamedNativeQuery that looks like this:</p>
  
  <pre><code>@Entity
  @NamedNativeQuery(
      name = "myObject.myStoredProcedure",
      query = "call my_stored_procedure(:num, :name, :start_date, :end_date)",
      callable = true,
      readOnly=true,
      resultSetMapping="implicit"
  )
  @SqlResultSetMapping(
      name="implicit",
      entities=@EntityResult(entityClass=org.mycompany.object.MyObject.class)
  )
  public class MyObject implements Serializable {
  ...
  </code></pre>
  
  <p>But when I try to call it in my DAO like so:</p>
  
  <pre><code>List&lt;MyObject&gt; objects = (List&lt;MyObject&gt;) getHibernateTemplate().execute(new HibernateCallback() {
              @Override
              public Object doInHibernate(Session session) throws HibernateException {
                  return session.getNamedQuery("myObject.myStoredProcedure")
                  .setInteger("num", num)
                  .setString("name", name)
                  .setDate("start_date", startDate)
                  .setDate("end_date", endDate)
                  .list();
              }
          });
  </code></pre>
  
  <p>But I get this error:</p>
  
  <pre><code>12 May 2010 10:55:43,040 100833 [http-8080-Processor23] ERROR org.hibernate.util.JDBCExceptionReporter  - Invalid parameter index 4.
  12 May 2010 10:55:43,042 100835 [http-8080-Processor23] FATAL org.mycompany.web.controller.BasePagingController  - org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
  org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
  </code></pre>
  
  <p>It seems like it's expecting another parameter, like a return parameter, but I tried adding a '?' to the call and all the Hibernate documentation suggests against this.</p>
  
  <p>Any help would be appreciated. Thanks</p>