Java getNamedQuery不检索数据

Java getNamedQuery不检索数据,java,sql,hibernate,Java,Sql,Hibernate,我使用org.hibernate.Session.getNamedQuery从xml文件中获取以下查询: <sql-query name="filterTraineesBySection"><![CDATA[ select usr.USERNAME, crs.NAME from TBLCOURSEROLE crsr inner join TBLCOURSE crs on crs.ID=:courseId and crsr.ROLEID=3 inner join U

我使用
org.hibernate.Session.getNamedQuery
从xml文件中获取以下查询:

<sql-query name="filterTraineesBySection"><![CDATA[ 
   select usr.USERNAME, crs.NAME
 from TBLCOURSEROLE crsr
 inner join TBLCOURSE crs on crs.ID=:courseId and crsr.ROLEID=3
 inner join USER_ usr on crsr.USERID=usr.ID
]]>
</sql-query> 

我使用上述方法如下:

    public ArrayList<String[]> getTraineesBySectionId(String sectionId) {
    String[] traineeDetails = null;
    ArrayList<String[]> traineesList = new ArrayList<String[]>();
    Query SgTrainees = null;
    SgTrainees = this.getSession().getNamedQuery("filterTraineesBySection");
    SgTrainees.setString("courseId", sectionId);
    Iterator trainees = SgTrainees.list().iterator();

    while (trainees.hasNext()) {
        Object[] tuple = (Object[]) trainees.next();
        traineeDetails = new String[2];
        traineeDetails[0] = (String) tuple[0];
        traineeDetails[1] = (String) tuple[1];
        traineesList.add(traineeDetails);;
    }


    return traineesList;

}
publicArrayList getTraineesBySectionId(String sectionId){
字符串[]TraineedDetails=null;
ArrayList traineesList=新建ArrayList();
查询值=null;
sg培训生=this.getSession().getNamedQuery(“filterTraineesBySection”);
sg.setString(“courseId”,sectionId);
迭代器培训生=sg培训生.list().Iterator();
while(培训生.hasNext()){
Object[]tuple=(Object[])培训生。next();
TraineedDetails=新字符串[2];
TraineedDetails[0]=(字符串)元组[0];
TraineedDetails[1]=(字符串)元组[1];
添加(培训细节);;
}
返回培训名单;
}

问题是,上面的查询在DBMS中成功执行,并检索了108行,而在java中它没有返回任何内容

我认为[我不确定]你的询问是错误的。在第4行设置参数时需要空格

示例:

crs.ID  <SPACE HERE>  =:courseId 
更新:

crs.ID  <SPACE HERE>  =:courseId 
您还需要设置参数,如下所示:

SgTrainees.setParameter("courseId", sectionId); 

而不是
sg培训生.setString(“courseId”,sectionId)

我猜他们的问题出在你的查询中。你能分享日志吗?是的,请分享你的日志,如@BalajiReddy所说。