hibernate 1对1  From 主表 会产生很多查询子表sql例如 主表 A  子表B 子表CA表 1对1 B表
A表 1对1 C表hql语句hql: from A order by id很产生select ..... from A order by idselect ..... from B order by idselect ..... from C order by id 等小弟新人 望高人指点下以下是配置文件A:
<one-to-one name="bid" class="B" cascade="all"></one-to-one>
<one-to-one name="cid" class="C" cascade="all" ></one-to-one>B:<one-to-one name="aid" class="A" constrained="true"></one-to-one>C:
<one-to-one name="aid" class="A" constrained="true"></one-to-one>

解决方案 »

  1.   

    每一条A的记载意味着和它关联的B和C都会加载进来,因为是一对一关系
      

  2.   

    那岂不意味着 每次都会执行 B表 和 C表的 sql 那样会不会 效率很低啊 有没有解决的方法
      

  3.   

    <one-to-one name="bid" class="B" cascade="all" lazy="true"></one-to-one>
    <one-to-one name="cid" class="C" cascade="all" lazy="true"></one-to-one>
      

  4.   

    lazy="true"  只能用在list中  那样配置会报错误的