hibernate映射
1,多对一(单向)
<!--Class端--> <set name="students" inverse="true"><!-- inverse="true" 多的端不维护关系--> <key column="classesid"/> <one-to-many class="Student"/> </set> <!--Student端--> <many-to-one name="classes" column="classesid"/>
<!--Class端--> <set name="students" inverse="true"><!-- inverse="true" 多的端不维护关系--> <key column="classesid"/> <one-to-many class="Student"/> </set> <!--Student端--> <many-to-one name="classes" column="classesid"/>
8,多对多(单向)
- <set name="roles" table="t_user_role">
- <key column="userid"/>
- <many-to-many class="Role" column="roleid"/>
- </set>
<set name="roles" table="t_user_role"> <key column="userid"/> <many-to-many class="Role" column="roleid"/> </set>
9,多对多(双向)
- <set name="users" table="t_user_role" order-by="userid">
- <key column="roleid"/>
- <many-to-many class="User" column="userid"/>
- </set>
- <set name="roles" table="t_user_role">
- <key column="userid"/>
- <many-to-many class="com.bjsxt.hibernate.Role" column="roleid"/>
- </set>
<set name="users" table="t_user_role" order-by="userid"> <key column="roleid"/> <many-to-many class="User" column="userid"/> </set> <set name="roles" table="t_user_role"> <key column="userid"/> <many-to-many class="com.bjsxt.hibernate.Role" column="roleid"/> </set>
10,总结
10.1:<many-to-one> 会在表中添加字段的
10.2:cascade 不对查询有影响