当用<mang to one >元素和<one to one>元素组合实现双向一对一的关联时为什么生成的是外联结语句,而<mang to one >元素和Set元素的<one to many>组合实现双向一对多的关联却没有生成表连接语句。
双向一对一:
@Test
publicvoid testGet(){
//1. 默认情况下对关联属性使用懒加载
Department dept =(Department) session.get(Department.class,1);
System.out.println(dept.getDeptName());
//2. 所以会出现懒加载异常的问题.
session.close();
Manager mgr = dept.getMgr();
System.out.println(mgr.getClass());
System.out.println(mgr.getMgrName());
//3. 查询 Manager 对象的连接条件应该是 dept.manager_id = mgr.manager_id
//而不应该是 dept.dept_id = mgr.manager_id
mgr = dept.getMgr();
System.out.println(mgr.getMgrName());
}
select
manager0_.MGR_ID as MGR_ID1_2_1_,
manager0_.MGR_NAME as MGR_NAME2_2_1_,
department1_.DEPT_ID as DEPT_ID1_1_0_,
department1_.DEPT_NAME as DEPT_NAM2_1_0_,
department1_.MGR_ID as MGR_ID3_1_0_
from
MANAGERS manager0_
left outer join
DEPARTMENTS department1_
on manager0_.MGR_ID=department1_.MGR_ID
where
manager0_.MGR_ID=?
select
department0_.DEPT_ID as DEPT_ID1_1_0_,
department0_.DEPT_NAME as DEPT_NAM2_1_0_,
department0_.MGR_ID as MGR_ID3_1_0_
from
DEPARTMENTS department0_
where
department0_.MGR_ID=?
双向一对n,没有表连接语句