hibernate基础(十一):抓取策略

1.意义:抓取策略研究的是一的一端怎么去查询多的一端。研究的对象是set集合

           应用场景:一对多,多对多

2.看个例子

<hibernate-mapping>
    <class name="domain.student" table="student">
        <id name="sid" column="sid" type="java.lang.Long" length="10">
            <generator class="increment"></generator>
        </id>
        <property name="sname" column="sname" type="java.lang.String" length="20">
        </property>
        <set name="courses" table="student_course" fetch="select">
            <key><column name="sid"></column></key>
            <many-to-many class="domain.Course" column="cid"></many-to-many>
        </set>
    </class>
</hibernate-mapping>

3.概念

           (1).set元素的fetch属性:select,subselect,join

                      select:查出所有多的内容。分两步,先查一后查多,根据ID

                      subselect:查出部门多的内容。分两步,先查一后查多,根据ID

                      join:左外连接,一步到位

           (2).针对set集合的加载策略和懒加载

           (3).若需求分析有多个学生时,join无效。join仅对一方且仅有一个有效

           (4).batch-size="3"    ==>    一次查3条

猜你喜欢

转载自blog.csdn.net/qq_40594696/article/details/87521870