例子:
one to many比如Class和Student吧就是一个班级对应多个学生
在Class类中追加集合属性 Set students;
在Class的配置文件中追加(Class.hbm.xml)
<!-- 设置集合属性 -->
<set name="students" lazy="false" fetch="join" cascade="all" inverse="true">
<!-- 设置关联字段 -->
<key column="classId" />
<!-- 设置关联关系 -->
<one-to-many class="Studnet" />
</set>
将Studnet中的classId属性去掉换成 Class class;
在Student的配置文件中(Student.hbm.xml)
class="Class">
×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
如上所示,如果一个班级同时对应多个学生和多个教师的情况下,我想配置教师表
是在
one-to-many class="Studnet"
这个下面在加一行
one-to-many class="Teacher" 吗?
还有
key column="classId"
这里面的classId是主动在ClassEntity里面设置为主键,还是会在Class里面自动生成为外键呢。求大神帮助。