双向关联多对多

inverse:反转

 

1) inverse="false" 表示为主控方,主控方负责维护关联关系,一般在一对多关系中,把多的一方设置为inverse="false"。

 

2) lazy="false表示是延迟加载,当为true时,启动延迟加载,如两个关联a,b不延迟加载时可能加载a时候,也把b加载了,但你可能没用b,只用a了,这就造成了浪费,延迟加载时表示用到b时才加载。

学生Student.hbm.xml:
<hibernate-mapping>
    <class name="com.ssh.Student" table="student" schema="dbo" catalog="sshcourse">
        <id name="stuId" type="integer">
            <column name="stu_id" />
            <generator class="native" />
        </id>
        <property name="stuName" type="string">
            <column name="stu_name" length="50" />
        </property>
        <property name="stuPwd" type="string">
            <column name="stu_pwd" length="50" />
        </property>
        <set name="courses"
        table="course_student_table"
        cascade="save-update"
        inverse="false" 
        lazy="false">
        <key column="stu_id"></key>
        <many-to-many class="com.ssh.Course" column="cou_id"></many-to-many>
        </set>
    </class>
</hibernate-mapping>
课程Course.hbm.xml:
<hibernate-mapping>
    <class name="com.ssh.Course" table="course" schema="dbo" catalog="sshcourse">
        <id name="couId" type="integer">
            <column name="cou_id" />
            <generator class="native" />
        </id>
        <property name="couName" type="string">
            <column name="cou_name" length="50" />
        </property>
        <property name="couDis" type="string">
            <column name="cou_dis" length="50" />
        </property>
        <set name="students"
        table="course_student_table"
        cascade="save-update"
        inverse="true">
        <key column="cou_id"></key>
        <many-to-many class="com.ssh.Student" column="stu_id"></many-to-many>
        </set>
    </class>
</hibernate-mapping>
他们之间是通过course_student_table学生课程表关联的

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值