hibernate多对多关联映射(单向User--->Role)
具体映射:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <class name="com.bjpowernode.hibernate.User" table="t_user"> 2 <id name="id"> 3 <generator class="native"/> 4 </id> 5 <property name="name"/> 6 <set name="roles" table="t_user_role"> 7 <key column="user_id"/> 8 <many-to-many class="com.bjpowernode.hibernate.Role" column="role_id" /> 9 </set> 10 </class>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <class name="com.bjpowernode.hibernate.Role" table="t_role"> 2 <id name="id"> 3 <generator class="native"/> 4 </id> 5 <property name="name"/> 6 </class>
public class User {
private int id;
private String name;
private Set roles;
//省略set()、get()方法
}
public class IdCard {
private int id;
private String name;
//省略set()、get()方法
}