Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java &引用;SQLException:缺少输入或输出参数";尽管已经明确注册_Java_Spring_Jpa_Stored Procedures_Entitymanager - Fatal编程技术网

Java &引用;SQLException:缺少输入或输出参数";尽管已经明确注册

Java &引用;SQLException:缺少输入或输出参数";尽管已经明确注册,java,spring,jpa,stored-procedures,entitymanager,Java,Spring,Jpa,Stored Procedures,Entitymanager,我有一个spring引导应用程序,它使用JPA和一个自定义实现来调用存储过程。问题是,在执行调用时,我得到了“在索引::7处缺少IN或OUT参数” 实现如下所示: public class DbLogImpl implements DbLogCustom { @PersistenceContext private EntityManager em; @Override public Long callInsertLog(Long firstId, Long se

我有一个spring引导应用程序,它使用JPA和一个自定义实现来调用存储过程。问题是,在执行调用时,我得到了“在索引::7处缺少IN或OUT参数”

实现如下所示:

public class DbLogImpl implements DbLogCustom {
    @PersistenceContext
    private EntityManager em;

    @Override
    public Long callInsertLog(Long firstId, Long secondId, Long process, Long subProcess, Long logLevelId, String message, String stacktrace) {

        Long logId = null;

        StoredProcedureQuery proc = em.createStoredProcedureQuery("logging_pk.insert_log");
        proc.registerStoredProcedureParameter(0, Long.class, IN);
        proc.registerStoredProcedureParameter(1, Long.class, IN);
        proc.registerStoredProcedureParameter(2, Long.class, IN);
        proc.registerStoredProcedureParameter(3, Long.class, IN);
        proc.registerStoredProcedureParameter(4, Long.class, IN);
        proc.registerStoredProcedureParameter(5, String.class, IN);
        proc.registerStoredProcedureParameter(6, String.class, IN);
        proc.setParameter(0, firstId);
        proc.setParameter(1, secondId);
        proc.setParameter(2, process);
        proc.setParameter(3, subProcess);
        proc.setParameter(4, logLevelId);
        proc.setParameter(5, message);
        proc.setParameter(6, stacktrace);
        proc.registerStoredProcedureParameter(7, Long.class, OUT);
        proc.execute();

        logId = (Long) proc.getOutputParameterValue(7);

        return logId;
    }
}
CREATE OR REPLACE PACKAGE logging_pk AS

    PROCEDURE insert_log (
        i_first_id                      NUMERIC,
        i_second_id                     NUMERIC,
        i_process                       NUMERIC,
        i_sub_process                   NUMERIC,
        i_log_level_id                  NUMERIC,
        i_message                       VARCHAR2,
        i_stacktrace                    VARCHAR2,
        o_log_id                    OUT NUMERIC
    );

END;
我的包看起来像这样:

public class DbLogImpl implements DbLogCustom {
    @PersistenceContext
    private EntityManager em;

    @Override
    public Long callInsertLog(Long firstId, Long secondId, Long process, Long subProcess, Long logLevelId, String message, String stacktrace) {

        Long logId = null;

        StoredProcedureQuery proc = em.createStoredProcedureQuery("logging_pk.insert_log");
        proc.registerStoredProcedureParameter(0, Long.class, IN);
        proc.registerStoredProcedureParameter(1, Long.class, IN);
        proc.registerStoredProcedureParameter(2, Long.class, IN);
        proc.registerStoredProcedureParameter(3, Long.class, IN);
        proc.registerStoredProcedureParameter(4, Long.class, IN);
        proc.registerStoredProcedureParameter(5, String.class, IN);
        proc.registerStoredProcedureParameter(6, String.class, IN);
        proc.setParameter(0, firstId);
        proc.setParameter(1, secondId);
        proc.setParameter(2, process);
        proc.setParameter(3, subProcess);
        proc.setParameter(4, logLevelId);
        proc.setParameter(5, message);
        proc.setParameter(6, stacktrace);
        proc.registerStoredProcedureParameter(7, Long.class, OUT);
        proc.execute();

        logId = (Long) proc.getOutputParameterValue(7);

        return logId;
    }
}
CREATE OR REPLACE PACKAGE logging_pk AS

    PROCEDURE insert_log (
        i_first_id                      NUMERIC,
        i_second_id                     NUMERIC,
        i_process                       NUMERIC,
        i_sub_process                   NUMERIC,
        i_log_level_id                  NUMERIC,
        i_message                       VARCHAR2,
        i_stacktrace                    VARCHAR2,
        o_log_id                    OUT NUMERIC
    );

END;
如果这是我唯一的程序,我很可能会承认失败并尝试另一种方法。 (我已经设法让它与本机查询一起工作,但没有实际获得输出参数值。)

但是,我有另一个存储过程调用,它的设置与此完全相同,并且运行良好。唯一的区别是参数的名称和数量(工作参数有3个输入和1个输出,输出也是最后一个)

我不明白为什么一个工作正常,而另一个工作不正常

编辑:
因为我在发布这个问题之前发现了这个问题,所以我决定省略很多与这个问题无关的代码,但我将把它留在这里,让其他人去发现。

在写这个问题时,我突然有了一个想法

事实证明,解决方案相当简单

显然,不接受将字符串参数设置为null。通过引入空检查并将空字符串(本例中的stacktrace参数)设置为空字符串,解决了这个问题

把这个留在这里以防其他人遇到这个问题