title: Is it possible to invoke sql server 2008 stored procedures using Hibernate Query?
body: <p>I am trying to call a stored procedure using Hibernate's Query class:</p>
  
  <pre><code>Query q = ssn.createSQLQuery("{ ? = call SEARCH_RESULT(?,?,?) }");
  
  int idx = 0;
  q.setParameter(idx, sc.getId(), StandardBasicTypes.INTEGER); 
  q.setString(++idx, sc.getNum() == null ? null : sc.getNum()
          .toString()); // second parameter
  q.setString(++idx, sc.getName());
  List list = q.list();
  </code></pre>
  
  <p>But it gives following exception, although there is no 4th parameter:
  Request helpful suggestions and potential solution.</p>
  
  <pre><code>com.microsoft.sqlserver.jdbc.SQLServerException: The value is not set for the parameter number 4.
      com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)
      com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildParamTypeDefinitions(SQLServerPreparedStatement.java:262)
      com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildPreparedStrings(SQLServerPreparedStatement.java:221)
      com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doPrepExec(SQLServerPreparedStatement.java:598)
      com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:386)
      com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
      com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
      com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
      com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
      com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
      com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:283)
      org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
      org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
      org.hibernate.loader.Loader.doQuery(Loader.java:802)
      org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
      org.hibernate.loader.Loader.doList(Loader.java:2533)
      org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
      org.hibernate.loader.Loader.list(Loader.java:2271)
      org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
      org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
      org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
      org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
  </code></pre>