读书人

hibernate的内外联接查询

发布时间: 2012-10-05 15:34:34 作者: rapoo

hibernate的内,外连接查询
hibernate虽然提供很多已经关联好的配置文件来做关联,但是如果配置不当,会使得hibernate的性能优势变成劣势,所以很多时候我们还是需要用到hibernate提供的 hql语句关联这样就能够大大提高性能而不用去劳心配置映射文件。

hql的连接和sql差不多 inner join / left outer join/ right outer join/full join

实体类 Student 班级 Cls 学校 School
stuId clsId schoolId
stuName clsName schoolName
Cls School


from Student student inner join student.Cls as cls 内连接,hql并不存在select * …… 这里需要进行关联, 也就是说我们并没有想sql那样 用 select * from tablea a inner join tableb b on a.id=b.id hql会自动用配置文件中你所配置的列和 关联表的主键进行关联。

from Student student inner join student.Cls as cls left join cls.School as school with school.schoolName like '湖北工业大学'; 你也可以对你想要关联的对象加上限定的条件。

读书人网 >软件架构设计

热点推荐