hibernate学习笔记第11讲-多对多关联映射many-to-many

单向映射


 

hibernate多对多关联映射(单向User---->Role)

 

具体映射方式:

         <set name="roles" table="t_user_role">

                   <key column="userid"/>

                   <many-to-many class="com.bjsxt.hibernate.Role" column="roleid"/>

         </set>

 

双向映射:



          hibernate多对多关联映射(双向User<---->Role)

 

映射方法:

                   <set name="roles" table="t_user_role">

                            <key column="userid"/>

                            <many-to-many class="com.bjsxt.hibernate.Role" column="roleid"/>

                   </set>

table属性值必须和单向关联中的table属性值一致

<key>column属性值要与单向关联中的<many-to-many>标签中的column属性值一致

<many-to-many>中的column属性值要与单向关联中<key>标签的column属性值一致

         

猜你喜欢

转载自lizhao6210-126-com.iteye.com/blog/1698585