mySQL 延迟 查询主表

  • A+
所属分类:数据库技术

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

例:

  1. <hibernate-mapping>
  2. <class name="com.pojo.Sortp" table="sortp" catalog="shjdc">
  3. <id name="id" type="java.lang.Integer">
  4. <column name="Id" />
  5. <generator class="assigned" />
  6. </id>
  7. <property name="name" type="java.lang.String">
  8. <column name="Name" length="40" not-null="true" />
  9. </property>
  10. <set name="productses" inverse="true" cascade="all" lazy="true">
  11. <key>
  12. <column name="Sortid" not-null="true" />
  13. </key>
  14. <one-to-many class="com.pojo.Products" />
  15. </set>
  16. </class>
  17. </hibernate-mapping>

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