【发布时间】:2018-01-03 21:50:03
【问题描述】:
我通过以下方式调用下一个查询:
resultObject = em.createNativeQuery(sql)
.setParameter(1, codEntidad)
.setParameter(2, nroLote)
.getResultList()
;
(codEntidad, nroLote are Integer) 然后给出下一个错误:
内部异常:org.postgresql.util.PSQLException:错误:el 运算符不存在:数字 = 字符变化
提示:Ningún operador 一致 con el nombre y el tipo de los 论据。 Puede ser necesario agregar conversions explícitas de 提示。
当前位置:4539
错误代码:0
但是当我复制结果查询并替换“?”使用数字并在 pgAdim 中执行查询,它可以正常工作。
select c.nro_ci, c.nombre_completo, c.nro_operacion, c.moneda, c.nro_lote,
c.faja_inform, c.cod_entidad, sum(c.saldo_operacion) saldo_operacion,
sum(c.mto_capital) mto_capital, sum(c.val_int_adelantado)
val_int_adelantado, sum(c.int_dia_pago) int_dia_pago,
sum(c.monto_a_pagar) monto_a_pagar
from (SELECT p.nro_documento nro_ci, p.nom_completo nombre_completo,
c.operacion nro_operacion, s.nro_solicitud, s.cod_moneda moneda,
sc.nro_cuota, sc.mto_capital saldo_operacion, sc.fec_vto_habil
fec_vencimiento, next_work_day3( CASE
WHEN to_char(sc.fec_vto_habil, 'MM') = '02' THEN
last_day(sc.fec_vto_habil)
ELSE to_date('30/'||to_char(sc.fec_vto_habil, 'MM/YYYY'), 'DD/MM/YYYY') END) fec_pago,
case
when sc.fec_vto_habil > next_work_day3( CASE WHEN to_char(sc.fec_vto_habil, 'MM') = '02' THEN last_day(sc.fec_vto_habil)
ELSE to_date('30/'||to_char(sc.fec_vto_habil, 'MM/YYYY'), 'DD/MM/YYYY')
END)
then 0
else next_work_day3( CASE
WHEN to_char(sc.fec_vto_habil, 'MM') = '02' THEN
last_day(sc.fec_vto_habil)
ELSE to_date('30/'||to_char(sc.fec_vto_habil, 'MM/YYYY'), 'DD/MM/YYYY')
END) - to_date(to_char(sc.fec_vto_habil, 'DD/MM/YYYY'), 'DD/MM/YYYY')
end dias_interes, sc.mto_capital, sc.val_int_adelantado,
case
when sc.fec_vto_habil > next_work_day3( CASE WHEN to_char(sc.fec_vto_habil, 'MM') = '02' THEN last_day(sc.fec_vto_habil)
ELSE to_date('30/'||to_char(sc.fec_vto_habil, 'MM/YYYY'), 'DD/MM/YYYY')
END)
then round((sc.mto_capital * 0 * 21) / 36500)
else round((sc.mto_capital * (next_work_day3(CASE WHEN to_char(sc.fec_vto_habil, 'MM') = '02' THEN last_day(sc.fec_vto_habil)
ELSE to_date('30/'||to_char(sc.fec_vto_habil, 'MM/YYYY'), 'DD/MM/YYYY')
END) - to_date(to_char(sc.fec_vto_habil, 'DD/MM/YYYY'), 'DD/MM/YYYY')) * 21) / 36500)
end int_dia_pago,
case
when sc.fec_vto_habil > next_work_day3( CASE WHEN to_char(sc.fec_vto_habil, 'MM') = '02' THEN last_day(sc.fec_vto_habil)
ELSE to_date('30/'||to_char(sc.fec_vto_habil, 'MM/YYYY'), 'DD/MM/YYYY')
END)
then (sc.mto_capital - sc.val_int_adelantado) - round((sc.mto_capital * 0
* 21) / 36500)
else
(sc.mto_capital - sc.val_int_adelantado) - round((sc.mto_capital *
(next_work_day3( CASE WHEN to_char(sc.fec_vto_habil, 'MM') = '02'
THEN last_day(sc.fec_vto_habil)
ELSE to_date('30/'||to_char(sc.fec_vto_habil,
'MM/YYYY'), 'DD/MM/YYYY')
END) - to_date(to_char(sc.fec_vto_habil,
'DD/MM/YYYY'), 'DD/MM/YYYY')) * 21) / 36500)
end monto_a_pagar, c.faja faja_inform, s.fec_insercion, c.nro_lote, c.cod_entidad
FROM pr_solicitudes s, pr_sol_cuotas sc, mi_com_cartera c, ba_personas p
WHERE s.nro_solicitud = c.nro_solicitud AND p.cod_persona = s.cod_persona
AND sc.nro_solicitud = s.nro_solicitud AND sc.nro_cuota <> 0) c
where c.cod_entidad = ?-->@COD_ENTIDAD and c.nro_lote = ?-->@NRO_LOTE.
group by c.nro_ci, c.nombre_completo, c.nro_operacion, c.moneda, c.nro_lote, c.faja_inform, c.cod_entidad order by 3;
【问题讨论】:
-
很难理解发生了什么以及您在示例中分享了什么。我不得不使用谷歌翻译来理解你的问题。我看到了这个问题的其他几个例子。从本质上讲,您的密钥似乎需要一个整数,而您正在传递一个字符串,反之亦然。您可能需要转换它们以匹配查询的预期。
-
"createNativeQuery" 不接受 JDBC 样式参数 (
?)。它接受编号参数(?1、?2等)。
标签: java postgresql jpa