当HQL返回错误时,SQL开发人员返回结果

时间:2016-05-18 13:19:14

标签: hibernate java-ee hql oracle-sqldeveloper

我正在开发一个项目,我必须生成一个HQL查询才能在JEE项目中完成任务。我的HQL查询是:

requete.append("SELECT elec, MIN(tour.datScrutin) dat FROM HbEleElection elec, HbEleTourScrutin tour");
    requete.append(" WHERE elec.idEtaElection <> "+ cstRepository.getIdConstanteByLibelle("ETAT_ELECTION_TERMINEE"));
    requete.append(" AND elec.id = tour.idElection");
    requete.append(" AND elec.zzzDsuEng is null");
    requete.append(" GROUP BY elec.lbcElection");
    requete.append(" ORDER BY dat "); 

但结果却一无所获。

我设法清理了东西,这是我的SQL开发人员返回我想要的结果的SQL查询。

SELECT elec.lbc_election,
   MIN(tour.dat_Scrutin) dat
FROM Ele_Election elec,
     Ele_Tour_Scrutin tour
WHERE elec.id_Eta_Election <> 335
  AND elec.id_election = tour.id_Election
  AND elec.zzz_Dsu_Eng IS NULL
GROUP BY elec.lbc_Election
ORDER BY dat desc 
在我的HQL的java中

我得到了HQL的这个错误:

  

1 net.sf.hibernate.QueryException :,期望SELECT [SELECT elec,MIN(tour.datScrutin)dat FROM vdm.commun.scrutin.dao.hbbean.HbEleElection as elec,vdm.commun.scrutin.dao。 hbbean.HbEleTourScrutin tour WHERE elec.idEtaElection&lt;&gt; 335 AND elec.id = tour.idElection AND elec.zzzDsuEng为null GROUP BY elec.lbcElection ORDER BY dat]

1 个答案:

答案 0 :(得分:1)

我认为你错过了'elec.lbc_election'并尝试选择Bean名称,这就是错误即将来临的原因。只需尝试此查询

requete.append("SELECT elec.lbc_election, MIN(tour.datScrutin) as dat FROM HbEleElection elec, HbEleTourScrutin tour"); requete.append(" WHERE elec.idEtaElection <> "+ cstRepository.getIdConstanteByLibelle("ETAT_ELECTION_TERMINEE")); requete.append(" AND elec.id = tour.idElection"); requete.append(" AND elec.zzzDsuEng is null"); requete.append(" GROUP BY elec.lbcElection"); requete.append(" ORDER BY dat ");