从Hibernate/MySQL调用存储过程:参数索引超出范围(3>;个参数,即2)

从Hibernate/MySQL调用存储过程:参数索引超出范围(3>;个参数,即2),mysql,hibernate,stored-procedures,Mysql,Hibernate,Stored Procedures,在使用MySQL db时,在Hibernate中调用insert存储过程时,我收到以下错误: 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.hiber

在使用MySQL db时,在Hibernate中调用insert存储过程时,我收到以下错误:

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 > number of parameters, which is 2).
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [model_mapping_xml.TPayment]
CREATE PROCEDURE InsertPayment(
                    IN pIdAnother INT,  
                    IN pAmount DECIMAL(19,4)                                
                    )
BEGIN 
...       
END
MySQL数据库中的存储过程定义:

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 > number of parameters, which is 2).
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [model_mapping_xml.TPayment]
CREATE PROCEDURE InsertPayment(
                    IN pIdAnother INT,  
                    IN pAmount DECIMAL(19,4)                                
                    )
BEGIN 
...       
END
TPayment.hbm.xml文件包含:

<sql-insert callable="true" check="none">
    { call InsertPayment(?, ?) }
</sql-insert>
为什么它会说“3>参数数量”,而该程序的每个地方都有2个参数? (我可以用类似的方式调用deletePayment和modifyPayment存储过程,它们工作得很好…)

t付款映射:

<hibernate-mapping>
    <class name="model_mapping_xml.TPayment" table="TPayment" catalog="DB">
        <id name="idPayment" type="java.lang.Integer">
            <column name="IdPayment" />
            <generator class="identity" />
        </id>
        <version name="rowvers" type="timestamp" generated="always">
            <column name="Rowvers" length="19" not-null="true" />
        </version>
        <many-to-one name="another" class="model_mapping_xml.TAnother" fetch="select">
            <column name="IdAnother" not-null="true" />
        </many-to-one>
        <property name="amount" type="big_decimal">
            <column name="Amount" scale="4" not-null="true" />
        </property>
        <property name="date1" type="timestamp">
            <column name="Date1" length="19" not-null="false" />
        </property>
        <sql-insert callable="true" check="none">
            { call InsertPayment(?, ?) }
        </sql-insert>
        <sql-update callable="true" check="none">
            { call ModifyPayment(?, ?, ?, ?, ?) }
        </sql-update>
        <sql-delete callable="true" check="none">
            { call DeletePayment(?, ?) }
        </sql-delete>
    </class>
</hibernate-mapping>

{调用插入支付(?,)}
{呼叫修改支付(?,,,?,?)}
{调用DeletePayment(?,)}
其他映射:

<hibernate-mapping>
    <class name="model_mapping_xml.TAnother" table="TAnother" catalog="DB">
        <id name="idAnother" type="java.lang.Integer">
            <column name="IdAnother" />
            <generator class="identity" />
        </id>
        <property name="dateBegin" type="date">
            <column name="DateBegin" length="10" not-null="true" />
        </property>
        <property name="dateEnd" type="date">
            <column name="DateEnd" length="10" />
        </property>
        <property name="rowvers" type="timestamp">
            <column name="Rowvers" length="19" not-null="true" />
        </property>
        <set name="payment" table="TPayment" 
                inverse="true" lazy="true" fetch="select">
            <key>
                <column name="IdAnother" not-null="true" />
            </key>
            <one-to-many class="model_mapping_xml.TPayment" />
        </set>
    </class>
</hibernate-mapping>


post TPayment/TAnother定义,有时是一个与同一列映射到多个TimeUpdate定义相关的问题(这是xml映射,所以我想已经足够了)可能您缺少了一个与
TPayment.date1
columnHmm相关的
,但我在存储过程头中没有这个列(因为我不想让它出现在那里,date1是在存储过程中生成的,因此不需要通过参数传递它)。文档不是显式的,但我认为您不能只插入属性的子集,或者缺少如上所述的输出参数