2009-11-02 51 views
1

我使用以下HQL查詢嘗試加載一組對象,並根據在以下鏈接中找到的建議選擇一個Student對象。 http://www.javalobby.org/articles/hibernate-query-101/在HQL查詢中預加載對象

from gradebook.model.Student student where student.studentId=1 left join fetch student.scores 

我碰到下面的錯誤。 意外令牌:左邊第1行,第64列 我粘貼了下面我的映射文件的相關部分。

<set name="scores" inverse="true" lazy="true" table="score" fetch="select"> 
<key> 
<column name="student_id" not-null="true" /> 
</key> 
<one-to-many class="gradebook.model.Score" /> 
</set> 

回答

3

HQL語法錯誤。 JOIN子句在之前屬於WHERE子句。

HQL語法基於SQL語法。如果您不太瞭解SQL語法,那麼您也可能遇到HQL語法問題。我可以推薦你SQL tutorial at w3schools.com

祝你好運。

+0

謝謝,移動連接解決了問題。另外,我所引用的鏈接中的語法是錯誤的,我的SQL有點生疏,所以我將查看您發佈的教程鏈接。 – Jared 2009-11-02 15:31:31