MySQL db で作業中に Hibernate で挿入ストアド プロシージャを呼び出すと、次のエラーが表示されます。
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]
MySQL db のストアド プロシージャ定義:
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>
ストアド プロシージャの暗黙的な呼び出し:
// 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);
このプロシージャのパラメータがどこでも 2 つあるのに、「3 > パラメータ数」と表示されるのはなぜですか? (deletePayment および modifyPayment ストアド プロシージャを同様の方法で呼び出すことができ、正常に動作します...)。
TPayment マッピング:
<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>
T別のマッピング:
<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>