在jpa和oracle客户端中查询相同,结果不同

时间:2014-06-06 23:15:41

标签: java sql oracle jpa

可能会发生在entityManager.createNativeQuery(JPA)和任何oracle客户端(SQL)中运行相同的查询会产生不同的结果吗?

使用以下查询发生了我:

SELECT FITE_INSTID,
  fite_grado,
  SUM(lenguajeP) as lenguajeP,
  SUM(lenguajeG) as lenguajeG,
  SUM(lenguajeX) as lenguajeX,
  SUM(matematicasP) as matematicasP,
  SUM(matematicasG) as matematicasG,
  SUM(matematicasX) as matematicasX,
  SUM(cienciasP) as cienciasP,
  SUM(cienciasG) as cienciasG,
  SUM(cienciasX) as cienciasX,
  SUM(pensamientoP) as pensamientoP, 
  SUM(pensamientoG) as pensamientoG, 
  SUM(pensamientoX) as pensamientoX
  FROM
(SELECT f.FITE_INSTID,
  f.fite_anio,
  f.fite_grado,    
 (CASE WHEN f.FITE_TIPO_REPORTE_L IN ('08') THEN 1 ELSE 0 END) AS lenguajeP,
 (CASE WHEN f.FITE_TIPO_REPORTE_L IN ('05') THEN 1 ELSE 0 END) AS lenguajeG,
 (CASE WHEN f.FITE_TIPO_REPORTE_L NOT IN ('05','08') THEN 1 ELSE 0 END) AS lenguajeX,
 (CASE WHEN f.FITE_TIPO_REPORTE_M IN ('08') THEN 1 ELSE 0 END) AS matematicasP,
 (CASE WHEN f.FITE_TIPO_REPORTE_M IN ('05') THEN 1 ELSE 0 END) AS matematicasG,
 (CASE WHEN f.FITE_TIPO_REPORTE_L NOT IN ('05','08') THEN 1 ELSE 0 END) AS matematicasX,
 (CASE WHEN f.FITE_TIPO_REPORTE_C IN ('08') THEN 1 ELSE 0 END) AS cienciasP,
 (CASE WHEN f.FITE_TIPO_REPORTE_C IN ('05') THEN 1 ELSE 0 END) AS cienciasG,
 (CASE WHEN f.FITE_TIPO_REPORTE_L NOT IN ('05','08') THEN 1 ELSE 0 END) AS cienciasX,
 (CASE WHEN f.FITE_TIPO_REPORTE_D IN ('08') THEN 1 ELSE 0 END) AS pensamientoP,
 (CASE WHEN f.FITE_TIPO_REPORTE_D IN ('05') THEN 1 ELSE 0 END) AS pensamientoG,
 (CASE WHEN f.FITE_TIPO_REPORTE_L NOT IN ('05','08') THEN 1 ELSE 0 END) AS pensamientoX
FROM Fichatecnica f 
WHERE 
  f.FITE_ESTADO=1 and  f.fite_instid is not null and f.fite_anio in (?,?,?,?)  and f.fite_instid=?) GROUP BY FITE_INSTID,
  fite_grado

使用jpa,matematicasP列中的结果为5,但在sql中结果为3。

有没有人遇到过这种问题?

谢谢!

2 个答案:

答案 0 :(得分:2)

这没有意义。您确定数据库的状态在您下面没有变化吗?在SQL中执行时,正确答案是3,在JPA中执行时答案是5,这两个都是正确的吗?

其次,你确定在每种情况下传递相同的绑定变量值吗?

答案 1 :(得分:0)

解决它..我不得不重置Oracle DB。 在它之后,oracle客户端(sql developer和sql plus)向我展示了我正在寻找的答案。 我不知道为什么这样做解决了这个问题。