spring boot invaliddataaccessapiusageexception-out/inout参数不可用

gdx19jrr  于 2021-07-16  发布在  Java
关注(0)|答案(0)|浏览(320)

我在springboot中使用了一个oracle存储过程,它有一些in/out参数。
当我获取out参数时,它抛出一个异常 invalidDataAccessApiUsageException: OUT/INOUT Parameter is not available: ent_mensaje. 这是存储过程定义

  1. create or replace PROCEDURE fon_anula_programacion (
  2. ent_numero_operacion IN NUMBER,
  3. ent_numero_fisico IN VARCHAR2,
  4. ent_mensaje IN OUT VARCHAR2,
  5. ent_canal_origen IN OUT VARCHAR2,
  6. ent_senal_proceso IN OUT VARCHAR2,
  7. ent_senal_commit IN OUT VARCHAR2,
  8. ent_sw_pos IN OUT NUMBER
  9. ) IS
  10. ...

实体类及其@namedStoredProcedurey

  1. @Getter
  2. @Setter
  3. @Entity
  4. @NoArgsConstructor
  5. @NamedStoredProcedureQueries({
  6. @NamedStoredProcedureQuery(name = "Valores.AnularAdicionFondoSif",
  7. procedureName = "FON.FON_ANULA_PROGRAMACION",
  8. resultClasses = DTOAnularAdicionSIF.class,
  9. parameters = {
  10. @StoredProcedureParameter(name = "ent_numero_operacion", type = BigDecimal.class, mode = ParameterMode.IN),
  11. @StoredProcedureParameter(name = "ent_numero_fisico", type = String.class, mode = ParameterMode.IN),
  12. @StoredProcedureParameter(name = "ent_mensaje", type = String.class, mode = ParameterMode.INOUT),
  13. @StoredProcedureParameter(name = "ent_canal_origen", type = String.class, mode = ParameterMode.INOUT),
  14. @StoredProcedureParameter(name = "ent_senal_proceso", type = String.class, mode = ParameterMode.INOUT),
  15. @StoredProcedureParameter(name = "ent_senal_commit", type = String.class, mode = ParameterMode.INOUT),
  16. @StoredProcedureParameter(name = "ent_sw_pos", type = BigDecimal.class, mode = ParameterMode.INOUT)
  17. }
  18. )
  19. })
  20. public class DTOAnularAdicionSIF {
  21. @Id
  22. @Column
  23. private BigDecimal Numero_operacion;
  24. @Column
  25. private String Numero_fisico;
  26. @Column
  27. private String Mensaje;
  28. @Column
  29. private String Canal_origen;
  30. @Column
  31. private String Senal_proceso;
  32. @Column
  33. private String Senal_commit;
  34. @Column
  35. private BigDecimal Sw_pos;
  36. }

我的params类

  1. public class AnularAdicionSIFParameters {
  2. @Params(name = "ent_numero_operacion",direction = Params.Direction.IN)
  3. private BigDecimal Numero_operacion;
  4. @Params(name = "ent_numero_fisico",direction = Params.Direction.IN)
  5. private String Numero_fisico;
  6. @Params(name = "ent_mensaje",direction = Params.Direction.INOUT)
  7. private String Mensaje;
  8. @Params(name = "ent_canal_origen",direction = Params.Direction.INOUT)
  9. private String Canal_origen;
  10. @Params(name = "ent_senal_proceso",direction = Params.Direction.INOUT)
  11. private String Senal_proceso;
  12. @Params(name = "ent_senal_commit",direction = Params.Direction.INOUT)
  13. private String Senal_commit;
  14. @Params(name = "ent_sw_pos",direction = Params.Direction.INOUT)
  15. private BigDecimal Sw_pos;
  16. }

发送参数

  1. AnularAdicionSIFParameters anularAdicionSIFParameters = AnularAdicionSIFParameters.builder()
  2. .Numero_operacion(BigDecimal.valueOf(Double.parseDouble(comprobante)))
  3. .Numero_fisico(numerofisico)
  4. .Senal_commit("S")
  5. .Canal_origen(canal)
  6. .Senal_proceso("S")
  7. .Mensaje("")
  8. .Sw_pos(BigDecimal.valueOf(0))
  9. .build();
  10. String response = repository.AnularAdicionReturnMensaje(anularAdicionSIFParameters);

存储库方法

  1. public String AnularAdicionReturnMensaje(AnularAdicionSIFParameters parameters) throws IllegalAccessException{
  2. String name_procedure = "Valores.AnularAdicionFondoSif";
  3. //super is the class who set the parameters and execute the procedure
  4. ResponseProcedure<AnularAdicionSIF> respuestaSif = super.runNamedStoredProcedure(name_procedure,parameters);
  5. return respuestaSif.getOutput().get("ent_mensaje").toString();
  6. }

设置参数并执行程序

  1. public ResponseProcedure<E> runNamedStoredProcedure(String nameProcedure, Object params) throws IllegalAccessException {
  2. StoredProcedureQuery storedProcedureQuery = em.createNamedStoredProcedureQuery(nameProcedure);
  3. Map<String, Object> output = new HashMap<>();
  4. Class<?> objectClass = params.getClass();
  5. Field[] extend = objectClass.getSuperclass().getDeclaredFields();
  6. Field[] base = objectClass.getDeclaredFields();
  7. Field[] allFields = new Field[extend.length + base.length];
  8. Arrays.setAll(allFields, i ->
  9. (i < extend.length ? extend[i] : base[i - extend.length]));
  10. for (Field field: allFields) {
  11. field.setAccessible(true);
  12. if (field.isAnnotationPresent(Params.class)) {
  13. Params param = field.getAnnotation(Params.class);
  14. if(param.direction() == Params.Direction.IN || param.direction() == Params.Direction.INOUT)
  15. storedProcedureQuery.setParameter(param.name(), (field.get(params) != null ) ? field.get(params) : "");
  16. }
  17. }
  18. storedProcedureQuery.execute();
  19. Arrays.stream(allFields).filter(field -> (field.getAnnotation(Params.class).direction() == Params.Direction.OUT || field.getAnnotation(Params.class).direction() == Params.Direction.INOUT))
  20. .forEach(ff ->{
  21. Params param = ff.getAnnotation(Params.class);
  22. output.put(param.name(), storedProcedureQuery.getOutputParameterValue(param.name()));
  23. });
  24. return new ResponseProcedure<E>(toList(storedProcedureQuery.getResultList()), output);
  25. }

错误是: OUT/INOUT parameter not available: ent_mensaje; nested exception is java.lang.IllegalArgumentException: OUT/INOUT parameter not available: ent_mensaje

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题