函数调用未正确设置参数

时间:2014-07-10 13:31:54

标签: java hibernate postgresql nativequery

我有这个方法:

public Long calculateMilisseconds(Calendario calendario, Date inicio, Date fim) throws ApplicationException {   
        try {


            StringBuffer sb = new StringBuffer();
            sb.append("select milissegundos_calendario(?,?,?)");

            Session session = HibernateUtil.currentSession();

            SQLQuery query = session.createSQLQuery(sb.toString());

            query.setInteger(0, calendario.getIdCalendario());
            query.setDate(1, inicio);
            query.setDate(2, fim);


            return (Long) query.uniqueResult();
        } catch (ApplicationException ae) {
            throw ae;
        } catch (Exception e) {
            log.error(e);
            log.error("# CalendarioHibernateDAO.calcularMilissegundosProdutivos(calendario, inicio, fim) : Long");
            throw new ApplicationException("ERRO.1", new String[]{"CalendarioHibernateDAO.calcularMilissegundosProdutivos"}, e, ApplicationException.ICON_ERRO);
        } finally {
            try {
                HibernateUtil.closeSession();
            } catch (Exception e) {
                log.error(e);
                log.error("# CalendarioHibernateDAO.calcularMilissegundosProdutivos(calendario, inicio, fim) : Long");
            }
        }
    }

设置参数#1和#2时,inicio和fim的值实际上是Date实例,看起来一切正常。但我得到以下例外:

10:21:53,877 INFO  [STDOUT] 10:21:53,877 ERROR [JDBCExceptionReporter] ERROR: function milissegundos_calendario(integer, unknown, unknown) does not exist.

我正在使用hibernate并为postgresql函数进行本机sql调用。我无法弄清楚出了什么问题。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

参数inicio不是日期,因为它需要整数query.setDate(1, inicio); query.setDate(2, fim);