Reputation: 178
I need call Oracle Function in MyBatis using Annotations.
My Mapper:
@Select("{ CALL #{outParam, jdbcType=NUMERIC, mode=OUT} := ORA_FUNC( "
+ "#{pNum1, jdbcType=NUMERIC, mode=IN},"
+ "#{pNum2, jdbcType=NUMERIC, mode=IN},"
+ "#{pNum3, jdbcType=NUMERIC, mode=IN} )}")
@Options(statementType = StatementType.CALLABLE)
@ResultType(Integer.class)
public Integer executeFunction(
@Param("map") Map<String, Object> carteira);
and my call to this signature:
Map<String, Object> mapParameters = new HashMap<String, Object>();
mapParameters.put("pNum1", carteira.getUnimedCarteira());
mapParameters.put("pNum2", carteira.getCodCarteira());
mapParameters.put("pNum3", carteira.getDigitoCarteira());
mapper.obterRedeBeneficiario(mapParameters);
return mapParameters.get("outParam").toString();
The outParam is null and the return of mapper is null too.
Can anyone help-me?
Upvotes: 2
Views: 5615
Reputation: 10004
create a domain class SpInOut class
class SpInOut{
private String outParam;
private int pNum1;
private int pNum2;
private int pNum3;
//Getters and setters
}
And you can change your maaper as below
@Select("{ #{outParam, jdbcType=NUMERIC, mode=OUT} = CALL ORA_FUNC( "
+ "#{pNum1, jdbcType=NUMERIC, mode=IN},"
+ "#{pNum2, jdbcType=NUMERIC, mode=IN},"
+ "#{pNum3, jdbcType=NUMERIC, mode=IN} )}")
@Options(statementType = StatementType.CALLABLE)
public void executeFunction(
SpInOut inOut);
Upvotes: 2