UserList POJO如下public class UserList implements java.io.Serializable {
private static final long serialVersionUID = 8246703686105352655L;
private Integer userId;
         ...............
private String memoInfo;
private Set<RoleList> rolelist=new HashSet<RoleList>();
         //get set方法肯定是有的
RoleList POJO如下public class RoleList implements java.io.Serializable {
        private static final long serialVersionUID = -1507454205769569163L;
private Integer roleId;
private Set<UserList> userlist=new HashSet<UserList>();
        //get set方法肯定是有的UserList hbm.xml文件如下<hibernate-mapping>
    <class name="com.xxx.UserList" table="UserList" schema="dbo" dynamic-insert="true" lazy="false" dynamic-update="true">
        <id name="userId" type="java.lang.Integer">
            <column name="UserID" />
            <generator class="native" />
        </id>
                            
        <set name="rolelist" cascade="save-update" inverse="true" lazy="false" table="UserList_RoleList">
            <key column="UserID" foreign-key="FK_UserList_RoleList_UserList"></key>
            <many-to-many class="com.xxxx.RoleList" column="RoleID"></many-to-many>
        </set>
        
    </class>
</hibernate-mapping>RoleList hbm.xml文件如下
[code=java]
<hibernate-mapping>
    <class name="com.xxx.RoleList" table="RoleList" dynamic-insert="true" lazy="false" dynamic-update="true" schema="dbo">
        <id name="roleId" type="java.lang.Integer">
            <column name="RoleID" />
            <generator class="native" />
        </id>
                            
          <set name="userlist" cascade="save-update" inverse="false" lazy="false" table="UserList_RoleList">
            <key column="RoleID" foreign-key="FK_UserList_RoleList_RoleList"></key>
            <many-to-many class="com.xxx.UserList" column="UserID"></many-to-many>
        </set>      
    </class>
</hibernate-mapping>
求好心人帮我看看我的这个配置

解决方案 »

  1.   

    上面代码好长,占楼描述下我的问题UserList    RoleList是多对多,通过UserList_RoleList表维护关系的,UserList_RoleList表就2个字段 UserID和RoleID,联合主键,数据库都配置了关系。现在是我想添加一个人员,同时把人员和角色的关系插入到UserList_RoleList表。 UserList插入成功,UserList_RoleList没有写入数据