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学生课程表关联的
分享到:
相关推荐
多对多双向关联 <br>注意映射规则: <set name="roles" table="t_user_role"><br> <key column="userid"/><br> <many-to-many class="com.bjsxt.hibernate.Role" column="roleid"/><br> </set><br> table...
13_传智播客JPA详解_JPA中的多对多双向关联实体定义与注解设置.rar
这里包含了多对一双向关联关系实现源码,希望对你有用。
NULL 博文链接:https://1028826685.iteye.com/blog/1525772
博文链接:https://weiweichen1985.iteye.com/blog/135677
NULL 博文链接:https://dreamzhong.iteye.com/blog/1200915
hibernate双向一对多关联映射(注解版)
Swift 双向关联tableView
Hibernate一对多双向自身关联demo代码
hibernate双向多对多关联映射(XML)
NULL 博文链接:https://yuanleilei628.iteye.com/blog/2209753
NULL 博文链接:https://huihai.iteye.com/blog/901171
Hibernate双向一对一关联映射(注解版)
Hibernate 一对一外键单向关联 Hibernate 一对一主键单向关联 Hibernate 一对一连接表单向关联 Hibernate 一对多外键单向关联 Hibernate 一对多连接表单向关联 Hibernate 多对一外键单向...Hibernate 多对多双向关联
博文链接:https://shaqiang32.iteye.com/blog/201309
13_JPA详解_JPA中的多对多双向关联实体定义与注解设置.zip 13_JPA详解_JPA中的多对多双向关联实体定义与注解设置.zip
Hibernate的映射策略:一对一双向关联映射,有所有的测试用例,用以证明从任何一端都可以加载另一端信息。