Hibernate多对多的映射

这是以前学Hibernate多对多的时候写的代码!这里介绍了2种不同方式的多对多的映射!例子以Emploree和Project为目标!其中一种配置为
<?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="com.softceo.hibernate.dto.Project" table="PROJECT" schema="SCOTT">
        <id name="proid" type="java.lang.Integer">
            <column name="PROID" precision="22" scale="0" />
            <generator class="assigned" />
        </id>
        <property name="proname" type="java.lang.String">
            <column name="PRONAME" length="20" not-null="true" />
        </property>
        <property name="prodescription" type="java.lang.String">
            <column name="PRODESCRIPTION" length="200" not-null="true" />
        </property>
        <set name="emplorees" table="R_TMP_PROJ" schema="SCOTT" cascade="save-update">
            <key>
                <column name="R_PROJ_ID" precision="22" scale="0" not-null="true" />
            </key>
            <many-to-many entity-name="com.softceo.hibernate.dto.Emploree">
                <column name="R_EMP_ID" precision="22" scale="0" not-null="true" />
            </many-to-many>
        </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="com.softceo.hibernate.dto.Project" table="PROJECT" schema="SCOTT">
        <id name="proid" type="java.math.BigDecimal">
            <column name="PROID" precision="22" scale="0" />
            <generator class="assigned" />
        </id>
        <property name="proname" type="java.lang.String">
            <column name="PRONAME" length="20" not-null="true" />
        </property>
        <property name="prodescription" type="java.lang.String">
            <column name="PRODESCRIPTION" length="200" not-null="true" />
        </property>
        <set name="RTmpProjs" inverse="true" cascade="save-update">
            <key>
                <column name="R_PROJ_ID" precision="22" scale="0" not-null="true" />
            </key>
            <one-to-many class="com.softceo.hibernate.dto.RTmpProj" />
        </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="com.softceo.hibernate.dto.RTmpProj" table="R_TMP_PROJ" schema="SCOTT">
        <composite-id>
            <key-many-to-one name="emploree" class="com.softceo.hibernate.dto.Emploree">
                <column name="R_EMP_ID" precision="22" scale="0" />
            </key-many-to-one>
            <key-many-to-one name="project" class="com.softceo.hibernate.dto.Project">
                <column name="R_PROJ_ID" precision="22" scale="0" />
            </key-many-to-one>
        </composite-id>
    </class>
</hibernate-mapping>

具体代码见附件!

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