0

I have this method:

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");
            }
        }
    }

When setting parameter #1 and #2, the values for inicio and fim are actually Date instances, look like that everything is ok. But I got the following exception:

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

I am using hibernate and making a native sql call for a postgresql function. I can't figure out what is wrong. Any thoughts?

Rafael dAS
  • 119
  • 4
  • How is the function defined? –  Jul 10 '14 at 13:33
  • CREATE OR REPLACE FUNCTION milissegundos_calendario(timestamp without time zone, timestamp without time zone, integer) RETURNS double precision AS – Rafael dAS Jul 10 '14 at 13:34
  • You pass a `Date` as the third parameter whereas the function expects an integer. And you should use a `java.sql.Timestamp` for the first and second parameter, not a `java.sql.Date` (or `java.util.Date`). Also what does `getIdCalendario()` return? –  Jul 10 '14 at 13:38
  • Thanks... Post your answer. – Rafael dAS Jul 10 '14 at 13:47

1 Answers1

0

The parameter inicio is not date, as it expects integer query.setDate(1, inicio); query.setDate(2, fim);

Vipin CP
  • 3,642
  • 3
  • 33
  • 55