Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling stored procedure from Hibernate / MySQL: Parameter index out of range (3 > number of parameters, which is 2)
    primarykey
    data
    text
    <p>I receive the following error when calling insert stored procedure in Hibernate while working with MySQL db:</p> <pre><code>Hibernate: { call InsertPayment(?, ?) } sie 28, 2013 10:17:19 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: 0, SQLState: S1009 sie 28, 2013 10:17:19 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: Parameter index out of range (3 &gt; number of parameters, which is 2). Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [model_mapping_xml.TPayment] </code></pre> <p>Stored procedure definition in MySQL db:</p> <pre><code>CREATE PROCEDURE InsertPayment( IN pIdAnother INT, IN pAmount DECIMAL(19,4) ) BEGIN ... END </code></pre> <p>TPayment.hbm.xml file contains:</p> <pre><code>&lt;sql-insert callable="true" check="none"&gt; { call InsertPayment(?, ?) } &lt;/sql-insert&gt; </code></pre> <p>Implicit call of the stored procedure:</p> <pre><code>// calling the stored procedure to add payment TPayment newp = new TPayment(); newp.setAnother((TAnother) session.load(TAnother.class, 1)); newp.setAmount(BigDecimal.valueOf(20)); session.save(newp); </code></pre> <p>Why does it say "3 > number of parameters" where everywhere there are 2 parameters for this procedure? (I can call deletePayment and modifyPayment stored procedures in similar way and they work fine...).</p> <p>TPayment mapping:</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="model_mapping_xml.TPayment" table="TPayment" catalog="DB"&gt; &lt;id name="idPayment" type="java.lang.Integer"&gt; &lt;column name="IdPayment" /&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;version name="rowvers" type="timestamp" generated="always"&gt; &lt;column name="Rowvers" length="19" not-null="true" /&gt; &lt;/version&gt; &lt;many-to-one name="another" class="model_mapping_xml.TAnother" fetch="select"&gt; &lt;column name="IdAnother" not-null="true" /&gt; &lt;/many-to-one&gt; &lt;property name="amount" type="big_decimal"&gt; &lt;column name="Amount" scale="4" not-null="true" /&gt; &lt;/property&gt; &lt;property name="date1" type="timestamp"&gt; &lt;column name="Date1" length="19" not-null="false" /&gt; &lt;/property&gt; &lt;sql-insert callable="true" check="none"&gt; { call InsertPayment(?, ?) } &lt;/sql-insert&gt; &lt;sql-update callable="true" check="none"&gt; { call ModifyPayment(?, ?, ?, ?, ?) } &lt;/sql-update&gt; &lt;sql-delete callable="true" check="none"&gt; { call DeletePayment(?, ?) } &lt;/sql-delete&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>TAnother mapping:</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="model_mapping_xml.TAnother" table="TAnother" catalog="DB"&gt; &lt;id name="idAnother" type="java.lang.Integer"&gt; &lt;column name="IdAnother" /&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;property name="dateBegin" type="date"&gt; &lt;column name="DateBegin" length="10" not-null="true" /&gt; &lt;/property&gt; &lt;property name="dateEnd" type="date"&gt; &lt;column name="DateEnd" length="10" /&gt; &lt;/property&gt; &lt;property name="rowvers" type="timestamp"&gt; &lt;column name="Rowvers" length="19" not-null="true" /&gt; &lt;/property&gt; &lt;set name="payment" table="TPayment" inverse="true" lazy="true" fetch="select"&gt; &lt;key&gt; &lt;column name="IdAnother" not-null="true" /&gt; &lt;/key&gt; &lt;one-to-many class="model_mapping_xml.TPayment" /&gt; &lt;/set&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload