HIBERNATE 基于中间表(中间表包含其他属性 )多对多关联查询

配置文件:

用户表:

 

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="SysUser" table="sys_user" schema="dbo">
        <id name="userId" type="java.lang.String">
            <column name="USER_ID" length="10" />
            <generator class="assigned" />
        </id>
       ...
<!-- 与关联表建立一对多的关系 -->
        <set name="ufis" table="user_functions_info" lazy="false" inverse="true">
		    <key column="USER_ID" />
		    <one-to-many class="UserFunctionsInfo" />
	</set>
    </class>
</hibernate-mapping>

 

  职能表:

 

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="FunctionsInfo" table="functions_info" schema="dbo">
        <id name="fiId" type="java.lang.String">
            <column name="FI_ID" length="10" />
            <generator class="assigned" />
        </id>
        ...
    </class>
</hibernate-mapping>
 

 

关联表(含其他属性):

 

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="UserFunctionsInfo" table="user_functions_info" schema="dbo">
        <composite-id name="id" class="UserFunctionsInfo">
            <key-property name="userId" type="java.lang.String">
                <column name="USER_ID" length="10" />
            </key-property>
            <key-property name="fiId" type="java.lang.String">
                <column name="FI_ID" length="10" />
            </key-property>
        </composite-id>
        <property name="upgradePlan" type="java.lang.String">
            <column name="UPGRADE_PLAN" length="10" />
        </property>
        <property name="reachDatetime" type="java.util.Date">
            <column name="REACH_DATETIME" length="23" />
        </property>
        <property name="traineeSituation" type="java.lang.String">
            <column name="TRAINEE_SITUATION" length="8" />
        </property>
    </class>
</hibernate-mapping>

 

 

 

做法就是将多对多的关联,转换为连个与中间表一对多的关联。

你可能感兴趣的:(HIBERNATE 基于中间表(中间表包含其他属性 )多对多关联查询)