R – Pre loading objects in an HQL query

hibernatehql

I'm using the following HQL query to try and load a set of objects when I select a Student object based on the advice found at the following link.
http://www.javalobby.org/articles/hibernate-query-101/

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

I get the following error.
unexpected token: left near line 1, column 64
I've pasted the relevant section of my mapping file below.

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

Best Answer

The HQL syntax is wrong. The JOIN clause belongs before the WHERE clause.

The HQL syntax is based on the SQL syntax. If you don't know SQL syntax very well, you may run into trouble with HQL syntax as well. I can recommend you the SQL tutorial at w3schools.com.

Good luck.

Related Topic