I'd like to call a MySQL stored procedure from Java using MyBatis & Spring. Do I need to use a POJO to do it?
I'm using the following versions:
- Java 1.6
- MyBatis 3.2.2
- Spring / MyBatis
- 1.2 Spring 3.2.3
- MySQL 5.1
The following code snippets code does work.
Mapper XML:
<update id="calculateNonTaxableOrderAmount"
parameterType="CalculateNonTaxableAmountDTO"
statementType="CALLABLE" >
{ call sp_calc_non_taxable_order_amount(
#{orderNum,jdbcType=INTEGER,mode=IN},
#{nonTaxableAmount,jdbcType=DECIMAL,mode=OUT} )
}
</update>
The method on the DAO Interface:
public void calculateNonTaxableOrderAmount(CalculateNonTaxableAmountDTO dto);
CalculateNonTaxableAmountDTO:
public class CalculateNonTaxableAmountDTO {
private Long orderNum;
private BigDecimal nonTaxableAmount;
public Long getOrderNum() {
return orderNum;
}
public void setOrderNum(Long orderNum) {
this.orderNum = orderNum;
}
public BigDecimal getNonTaxableAmount() {
return nonTaxableAmount;
}
public void setNonTaxableAmount(BigDecimal nonTaxableAmount) {
this.nonTaxableAmount = nonTaxableAmount;
}
}
The above works great, but what I would like to do is something like this:
Mapper XML:
Note this missing parameterType attribute.
<update id="calculateNonTaxableOrderAmount"
statementType="CALLABLE" >
{ call sp_calc_non_taxable_order_amount(
#{orderNum,jdbcType=INTEGER,mode=IN},
#{nonTaxableAmount,jdbcType=DECIMAL,mode=OUT} )
}
</update>
The method on the DAO Interface:
public void calculateNonTaxableOrderAmount(
@Param("orderNum") Long orderNum,
@Param("nonTaxableAmount") BigDecimal nonTaxableAmount);
The DAO method is called with some code similar to:
BigDecimal nonTaxAmount = new BigDecimal(-1).setScale(2);
orderHeaderDAO.calculateNonTaxableOrderAmount(new Long(11111), nonTaxAmount);
System.out.println("nonTaxAmount = " + nonTaxAmount);
The code executes successfully, but the nonTaxAmount is never updated. The println prints out -1.
Any help, or guidance would be appreciated.