Hibernate 多对多映射实列 (复合主键)

               <id name="id" type="integer">
			<column name="userId" />
			<generator class="sequence">
				<param name="sequence">SEQ_IRCS_USER_ID</param>
			</generator>
	</id>
..................
       <set name="ircsGroups" table="TB_IRCS_USERGROUP" lazy="true" inverse="false"  cascade="save-update" batch-size="5"  sort="unsorted" >
            <key column="userId"/>
            <many-to-many class="net.p5w.common.po.ircs.IrcsGroup">
            <column name="groupCode"  not-null="true"  length="12"></column>
            <column name="stockcode"  not-null="true"   length="8" ></column>
            <column name="stocktype"  not-null="true"  length="1" ></column>
            </many-to-many>
        </set>
 以上为:IrcsUser.hbm.xml

 

 

 

 

	<composite-id>
			<key-property name="groupCode" type="string">
				<column name="groupCode" length="12" />
			</key-property>		
			<key-property name="stockCode" type="string">
				<column name="stockcode" length="8" />
			</key-property>
			<key-property name="stockType" type="string">
				<column name="stocktype" length="1" />
			</key-property>
	</composite-id>



<set name="ircsUsers" table="TB_IRCS_USERGROUP" lazy="true" inverse="false"  cascade="save-update" batch-size="5" sort="unsorted">
            <key>
            <column name="stockcode"  not-null="true"  length="8" ></column>
            <column name="stocktype"  not-null="true"  length="1" ></column>
            <column name="groupCode"  not-null="true"  length="12"></column>
            </key>
            <many-to-many class="net.p5w.common.po.ircs.IrcsUser" column="userId"/>
        </set> 
 以上为:IrcsGroup.hbm.xml

 

注意:set中的key 的顺序与实体类的属性顺序一致!!!!

 

 

你可能感兴趣的:(DAO,xml,.net,Hibernate)