日期:2014-05-18  浏览次数:20743 次

Nhibernate 多对多 延迟加载无效
有3张表 Part表 Ques表 Part_Ques中间表  
现在在Part表中对Ques配置了many-to-many,并且希望它延迟加载,也就是我在只读取partTitle的时候不要加载Ques,因为Ques表很大,查询很慢.
可是在下面的配置过程中发现Lazy="true"并没有如我所愿.
系统是正常的,因为在配置Exam_Part的关系的时候,Part可以延迟加载,可能是因为他们的关系是one-to-many吧~~ 这个many-to-many就一直不能延迟加载




这个是Part的配置
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
  assembly="RMSPExam.Domain"
  namespace="RMSPExam.Domain.Entities.PaperEntities">
  <class name="PaperPart" table ="T_Paper_Parts">
  <id name ="ID" column="ID" type="string" length="50">
  <generator class="uuid.hex"/>
  </id>
  <property name="PartNo" column="Part_No" type="string"/>
  <property name="PartTitle" column="Part_Title" type="string" length="2000"/>
  <bag name="PaperQuestions" lazy="true" table="T_PaperPart_Ques" inverse="true">
  <key column="Part_ID"/>
  <many-to-many column="Ques_ID" class="RMSPExam.Domain.Entities.PaperEntities.PaperQuestion"/>
  </bag >
  </class>
</hibernate-mapping>


Ques配置文件如下,
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
  assembly="RMSPExam.Domain"
  namespace="RMSPExam.Domain.Entities.PaperEntities">
  <class name="PaperQuestion" table ="T_Paper_Ques">
  <id name ="ID" column="ID" type="string" length="50">
  <generator class="uuid.hex"/>
  </id>
  <property name="QuestionContent" column="Ques_Content" type="binary"/>
  <join table="T_PaperPart_Ques" fetch="join">
  <key column="Ques_ID"/>
  <many-to-one name="PaperPart" column="Part_ID" class="RMSPExam.Domain.Entities.PaperEntities.PaperPart" lazy="proxy"/>
  </join>
  </class>
</hibernate-mapping>

------解决方案--------------------
次问题碰到过,是那个lazy=“proxy”干的!