mySQL延迟

来源:互联网 发布:高三复读 知乎 编辑:程序博客网 时间:2024/05/01 22:30

 在主外键表存在关系的时候如果加上"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的话,在执行查询主表的同时,相应的子表也会查询,添加了许多无用功。

原创粉丝点击