问题描述
我在 Spring Boot 中使用了一个 Oracle 存储过程,它有一些输入/输出参数。
当我得到一个 out 参数时它会抛出一个异常 invalidDataAccessApiUsageException: OUT/INOUT Parameter is not available: ent_mensaje.
这是存储过程定义
create or replace PROCEDURE fon_anula_programacion (
ent_numero_operacion IN NUMBER,ent_numero_fisico IN VARCHAR2,ent_mensaje IN OUT VARCHAR2,ent_canal_origen IN OUT VARCHAR2,ent_senal_proceso IN OUT VARCHAR2,ent_senal_commit IN OUT VARCHAR2,ent_sw_pos IN OUT NUMBER
) IS
...
带有@NamedStoredProcedureQuery 的实体类
@Getter
@Setter
@Entity
@NoArgsConstructor
@NamedStoredProcedureQueries({
@NamedStoredProcedureQuery(name = "Valores.AnularadicionFondoSif",procedureName = "FON.FON_ANULA_PROGRAMACION",resultClasses = DTOAnularadicionSIF.class,parameters = {
@StoredProcedureParameter(name = "ent_numero_operacion",type = BigDecimal.class,mode = ParameterMode.IN),@StoredProcedureParameter(name = "ent_numero_fisico",type = String.class,@StoredProcedureParameter(name = "ent_mensaje",mode = ParameterMode.INOUT),@StoredProcedureParameter(name = "ent_canal_origen",@StoredProcedureParameter(name = "ent_senal_proceso",@StoredProcedureParameter(name = "ent_senal_commit",@StoredProcedureParameter(name = "ent_sw_pos",mode = ParameterMode.INOUT)
}
)
})
public class DTOAnularadicionSIF {
@Id
@Column
private BigDecimal Numero_operacion;
@Column
private String Numero_fisico;
@Column
private String Mensaje;
@Column
private String Canal_origen;
@Column
private String Senal_proceso;
@Column
private String Senal_commit;
@Column
private BigDecimal Sw_pos;
}
我的参数类
public class AnularadicionSIFParameters {
@Params(name = "ent_numero_operacion",direction = Params.Direction.IN)
private BigDecimal Numero_operacion;
@Params(name = "ent_numero_fisico",direction = Params.Direction.IN)
private String Numero_fisico;
@Params(name = "ent_mensaje",direction = Params.Direction.INOUT)
private String Mensaje;
@Params(name = "ent_canal_origen",direction = Params.Direction.INOUT)
private String Canal_origen;
@Params(name = "ent_senal_proceso",direction = Params.Direction.INOUT)
private String Senal_proceso;
@Params(name = "ent_senal_commit",direction = Params.Direction.INOUT)
private String Senal_commit;
@Params(name = "ent_sw_pos",direction = Params.Direction.INOUT)
private BigDecimal Sw_pos;
}
发送参数
AnularadicionSIFParameters anularadicionSIFParameters = AnularadicionSIFParameters.builder()
.Numero_operacion(BigDecimal.valueOf(Double.parseDouble(comprobante)))
.Numero_fisico(numerofisico)
.Senal_commit("S")
.Canal_origen(canal)
.Senal_proceso("S")
.Mensaje("")
.Sw_pos(BigDecimal.valueOf(0))
.build();
String response = repository.AnularadicionReturnMensaje(anularadicionSIFParameters);
存储方法
public String AnularadicionReturnMensaje(AnularadicionSIFParameters parameters) throws illegalaccessexception{
String name_procedure = "Valores.AnularadicionFondoSif";
//super is the class who set the parameters and execute the procedure
ResponseProcedure<AnularadicionSIF> respuestaSif = super.runNamedStoredProcedure(name_procedure,parameters);
return respuestaSif.getoutput().get("ent_mensaje").toString();
}
设置参数并执行程序
public ResponseProcedure<E> runNamedStoredProcedure(String nameProcedure,Object params) throws illegalaccessexception {
StoredProcedureQuery storedProcedureQuery = em.createNamedStoredProcedureQuery(nameProcedure);
Map<String,Object> output = new HashMap<>();
Class<?> objectClass = params.getClass();
Field[] extend = objectClass.getSuperclass().getDeclaredFields();
Field[] base = objectClass.getDeclaredFields();
Field[] allFields = new Field[extend.length + base.length];
Arrays.setAll(allFields,i ->
(i < extend.length ? extend[i] : base[i - extend.length]));
for (Field field: allFields) {
field.setAccessible(true);
if (field.isAnnotationPresent(Params.class)) {
Params param = field.getAnnotation(Params.class);
if(param.direction() == Params.Direction.IN || param.direction() == Params.Direction.INOUT)
storedProcedureQuery.setParameter(param.name(),(field.get(params) != null ) ? field.get(params) : "");
}
}
storedProcedureQuery.execute();
Arrays.stream(allFields).filter(field -> (field.getAnnotation(Params.class).direction() == Params.Direction.OUT || field.getAnnotation(Params.class).direction() == Params.Direction.INOUT))
.forEach(ff ->{
Params param = ff.getAnnotation(Params.class);
output.put(param.name(),storedProcedureQuery.getoutputParameterValue(param.name()));
});
return new ResponseProcedure<E>(toList(storedProcedureQuery.getResultList()),output);
}
错误:OUT/INOUT parameter not available: ent_mensaje; nested exception is java.lang.IllegalArgumentException: OUT/INOUT parameter not available: ent_mensaje
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)