hibernate多对多关联映射

Posted on 2009-08-22 17:42  哥德巴赫猜  阅读(110)  评论(0)    收藏  举报

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属性值一致

 

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3