延迟加载:在hbm.xml里设置lazy是true 或者 false(一对多,多对多 默认延迟加载)
左外链接:在hbm.xml里设置outer-join 为 true(一对一 ,多对一 默认左外链接 --fetch (join/select)制定查询方式)
一下Session的方法都用于检索OID为1的Customer对象;
session.createQuery("from Customer as c where c.id=1")
session.createQuery("from Customer as c left join fetch c.orders where c.id=1")
在执行第一个方法时,将使用映射文件配置的检索策略。
在执行第二个方法时,在hql语句中显示制定的左外链接检索关联的order 对象,会覆盖映射文件中lazy的检索策略,采用左外连接策略(非延迟加载)