欢迎使用CSDN-markdown编辑器

来源:互联网 发布:js中小于等于 编辑:程序博客网 时间:2024/05/20 23:02
                           关于hibernate懒加载机制的查询                           分别有四张表                          成绩表sorce↗学生表tstudent↘↘班级表tclass                                     ↘课程表tcourse↗↗

(1) inner join
from Tstudent t (表的别名)inner join t.tclass;//hql的联合
Tstudent属性里有Tclass的属性(iterator是迭代,q.lierater()是查询,与q.list()相似)
查询出来obj对象为对应两个数组;
(2) fetch
from Tstudents t inner join fetch t.tclass//hql联合查询
fetch把tclass映射出来,对象为一个,只有tstudent对象,使用fetch可以获取tstudent所有对象
(3)from 表名
tstudent 为对象,tclass为代理,没有任何值
sql语句先获取student 信息,班级一个一个获取
使用典型懒加载机制,当需要时执行
(4)四表查询
from Tscore s inner s join fetch s.tcourse
inner join fetch s.tstudent ts
inner join fetch s.tstudent.tclass where ts.tno=?
from后面是类名, inner join fetch后面是当前对象的对象属性,如果对象属性下还有对象,就一层一层调用对象属性

0 0
原创粉丝点击