Hibernate 关联映射

多对一

<class name="Emp" table="emp">
    <id name="empno" column="EMPNO" type="int">
    <generator class="native"></generator>
    </id>
    <property name="ename"></property>
    <property name="job"></property>
    <property name="mgr"></property>
    <property name="hiredate"></property>
    <property name="sal"></property>
    <property name="comm"></property>
    <many-to-one name="dept" column="deptno" 
    class="com.mxthd.hibernate.bean.Dept">
    </many-to-one>
</class>

一对多

<class name="Dept" table="dept">
    <id name="deptno" column="deptno" type="int">
    <generator class="native"></generator>
    </id>
    <property name="dname"></property>
    <property name="loc"></property>
    <set name="emps">
    <key column="deptno"></key>
    <one-to-many class="com.mxthd.hibernate.bean.Emp"></one-to-many>
    </set>
</class>

原文链接:,转发请注明来源!

发表评论