2013-11-21 71 views
0

我以前org.hibernate.Session.getNamedQuery獲得從XML文件中的以下查詢:getNamedQuery不檢索數據

<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; 

} 

的問題是,上面的查詢執行成功地在DBMS中檢索108行,而在java中它不會返回任何東西!

回答

0

我認爲[我不確定]您的查詢是錯誤的。你需要空間,同時對線路設置參數4

例子:

crs.ID <SPACE HERE> =:courseId 

完整格式見下文:

inner join TBLCOURSE crs on crs.ID =:courseId and crsr.ROLEID=3 

更新時間:

,你也需要setParameter like follwoing:

SgTrainees.setParameter("courseId", sectionId); 

代替SgTrainees.setString("courseId", sectionId);

+0

我想這樣做,但什麼都沒有改變! –

+1

我猜他們是在你的查詢中的一些問題。你可以分享日誌嗎? – BDR

+0

是的,請分享您的日誌爲@BalajiReddy說。 – Yubaraj