代码之家  ›  专栏  ›  技术社区  ›  Jared

在HQL查询中预加载对象

  •  1
  • Jared  · 技术社区  · 15 年前

    当我根据下面链接中的建议选择一个学生对象时,我使用下面的HQL查询来尝试加载一组对象。 http://www.javalobby.org/articles/hibernate-query-101/

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

    我得到以下错误。 我已经在下面粘贴了映射文件的相关部分。

    <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>
    
    1 回复  |  直到 15 年前
        1
  •  3
  •   BalusC    15 年前

    HQL语法是错误的。JOIN子句属于 WHERE子句。

    SQL tutorial at w3schools.com .

    祝你好运