嘿伙计我在postgres SQL中有一个程序,我正在尝试使用jpa hibernate调用它,但是我收到了错误。
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(:ano,:mes,:codNre,:codMun,0 )AS f(descricao varchar,itens integer,quantidade bigint,valor numeric)]
我已经尝试将*替换为f但不能正常工作= \