SimpleJDBCCall Spring not execute

帅比萌擦擦* 提交于 2019-12-11 17:46:19

问题


I have this method

public void importarAdiantamento(ArrayList<LayoutArquivo> arquivos, Usuario usuario) throws Exception {

        try {

            for(LayoutArquivo arquivo : arquivos) {
                DateFormat fmt = new SimpleDateFormat("dd/MM/yyyy");    
                SqlParameterSource in = new MapSqlParameterSource()
                        .addValue("DATAVCM", new java.sql.Date(fmt.parse(arquivo.getVencimento()).getTime()))
                        .addValue("VALOR", arquivo.getValor())
                        .addValue("MOTIVO", arquivo.getCodMotivo())
                        .addValue("EMPRESA", arquivo.getCodEmpresa())
                        .addValue("NPARCELA", 1)
                        .addValue("TOTALPARCELA", 1)
                        .addValue("DOCUMENTO", arquivo.getDocumento())
                        .addValue("FUNCIONARIO", arquivo.getCodFunc())
                        .addValue("HISTORICO", "VALE IMPORTADO")
                        .addValue("EXPORTAR", 0)
                        .addValue("USUARIO", usuario.getCodigousuario())
                        .addValue("DUPLIC", 0)
                        .addValue("PROTOCOLO", "0");


                SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate)                                          
                        .withProcedureName(AdiantamentoQueries.importarAdiantamento())
                        .declareParameters(
                                new SqlParameter("DATAVCM", Types.DATE),
                                new SqlParameter("VALOR", Types.NUMERIC),
                                new SqlParameter("MOTIVO", Types.NUMERIC),
                                new SqlParameter("EMPRESA", Types.NUMERIC),
                                new SqlParameter("NPARCELA", Types.NUMERIC),
                                new SqlParameter("TOTALPARCELA", Types.NUMERIC),
                                new SqlParameter("DOCUMENTO", Types.VARCHAR),
                                new SqlParameter("FUNCIONARIO", Types.NUMERIC),
                                new SqlParameter("HISTORICO", Types.VARCHAR),
                                new SqlParameter("EXPORTAR", Types.NUMERIC),
                                new SqlParameter("USUARIO", Types.NUMERIC),
                                new SqlOutParameter("DUPLIC", Types.NUMERIC),
                                new SqlParameter("PROTOCOLO", Types.VARCHAR)
                         );


                System.out.println("executando o documento " + arquivo.getDocumento());
                jdbcCall.execute(in);
                System.out.println("terminou de executar o documento" + arquivo.getDocumento());

            }


        }catch (Exception e) {
            throw new Exception(e);
        }
    }

When arrive in line jdbcCall.execute(in); The execution hangs like you're waiting and not continue. No have idea what going on

I printed information in console and only this is printed

executando o documento 72527

Since I can only commit when all of the for records have been successfully completed, I had placed the @Transactional annotation but it did not work either

after run this method is java, this is a sessions in my database:


回答1:


  • Do you saw in database if your transaction is running?
  • Do you executed that procedure directly in database instead of run in java?
  • Not exists any process running in parallel causing a lock in database?

Hope I helped you.




回答2:


1) If you are running the jdbcCall in for loop, it is better to declare jdbcCall object outside the for loop. You don't need to create this object in each iteration.

2) When you use @Transactional, the method should not handle the exception with try-catch block. So, please remove the try-catch block and annotate the method as mentioned below.

@Transactional(rollbackFor=Exception.class)


来源:https://stackoverflow.com/questions/48748576/simplejdbccall-spring-not-execute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!