码迷,mamicode.com
首页 > Web开发 > 详细

hibernate-one-to-many

时间:2016-08-05 13:32:10      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

package hibernate.po;

import java.util.Set;

public class Dept {
    private int id;
    private String name;
    
    private Set<Memb> membs;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    public Set<Memb> getMembs() {
        return membs;
    }

    public void setMembs(Set<Memb> membs) {
        this.membs = membs;
    }
}
package hibernate.po;

public class Memb {
    private int id;
    private String username;
    private String password;

    private Dept dept;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Dept getDept() {
        return dept;
    }

    public void setDept(Dept dept) {
        this.dept = dept;
    }
}
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="hibernate.po">
    <class name="Dept" table="dept">
        <id name="id" column="id">
            <generator class="native" />
        </id>
        <property name="name" length="50" />
        <set name="membs">
            <key column="dept_id" foreign-key="fk_memb_dept"></key>
            <one-to-many class="Memb" />
        </set>
    </class>
</hibernate-mapping>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="hibernate.po">
    <class name="Memb" table="memb">
        <id name="id" column="id">
            <generator class="native" />
        </id>
        <property name="username" column="username" length="50" />
        <property name="password" column="password" length="50" />

        <many-to-one name="dept" foreign-key="fk_memb_dept">
            <column name="dept_id" />
        </many-to-one>
    </class>
</hibernate-mapping>

 

hibernate-one-to-many

标签:

原文地址:http://www.cnblogs.com/xiaowangzhi/p/5740750.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!