0
嘿傢伙我有一個程序在postgres SQL,我試圖調用它使用jpa休眠,但我得到錯誤。調用程序/函數JPA休眠
select * from myprocedure(2016, 3, 0, 0,0)
AS f(descricao varchar, itens integer, quantidade bigint, valor numeric)
這裏是什麼即時嘗試在java中做什麼。
StringBuilder sb = new StringBuilder();
sb.append(" SELECT * ");
sb.append(" FROM myprocedure(");
sb.append(" :ano , ");
if (Util.isNotNull(mes)) {
sb.append(":mes , ");
}
sb.append(" :codNre , ");
sb.append(" :codMun , ");
sb.append(" 0) ");
sb.append(" AS f(descricao varchar, itens integer, quantidade bigint, valor numeric) ");
TypedQuery<Tuple> query = em.createQuery(sb.toString(), Tuple.class);
query.setParameter("ano", ano);
if (Util.isNotNull(mes)) {
query.setParameter("mes", mes);
}
query.setParameter("codNre", codNre);
query.setParameter("codMun", codMun);
List<ResumoDistribuicaoMerendaDTO> listaRetorno = new ArrayList<ResumoDistribuicaoMerendaDTO>();
List<Tuple> results = query.getResultList();
for (Tuple result : results) {
ResumoDistribuicaoMerendaDTO resumoMerenda = new ResumoDistribuicaoMerendaDTO();
resumoMerenda.setDescricaoAlimento(result.get(0).toString());
resumoMerenda.setItens(Integer.valueOf(result.get(1).toString()));
resumoMerenda
.setQuantidade(result.get(2) == null ? new Long(0) : Long.parseLong(result.get(2).toString()));
resumoMerenda.setValor(result.get(3) == null ? new BigDecimal(0)
: BigDecimal.valueOf(Double.parseDouble(result.get(3).toString())));
listaRetorno.add(resumoMerenda);
}
和異常:
java.lang.IllegalArgumentException異常:org.hibernate.hql.internal.ast.QuerySyntaxException:意外的標記:*近線1,第9欄[SELECT * FROM myprocedure(:肛門,:MES,:codNre,:codMun,0)爲f(descricao VARCHAR,itens整數,quantidade BIGINT,英勇數字)
我已經嘗試更換f的*,但沒有工作= \
看看這個:https://www.mkyong.com/hibernate/how-to-call-存儲 - 程序功能於休眠/ –