MySQL延迟 查询主表

     在主外键表存在关系的时候如果加上"lazy=true"的话,则表明延迟,即只查询主表中的内容,而不查询外键表中的内容。

    

<hibernate-mapping> 
<class name="com.pojo.Sortp" table="sortp" catalog="shjdc"> 
<id name="id" type="java.lang.Integer"> 
<column name="Id" /> 
<generator class="assigned" /> 
</id> 
<property name="name" type="java.lang.String"> 
<column name="Name" length="40" not-null="true" /> 
</property> 
<set name="productses" inverse="true" cascade="all" lazy="true"> 
<key> 
<column name="Sortid" not-null="true" /> 
</key> 
<one-to-many class="com.pojo.Products" /> 
</set> 
</class> 
</hibernate-mapping> 

  一般情况下就是把lazy设为true,而不是false,因为,假如设为false的话,在执行查询主表的同时,相应的子表也会查询,添加了许多无用功。

猜你喜欢

转载自www.cnblogs.com/68xi/p/9466188.html