hibernate多对一关系的配置及操作

 Sort.java
package com.daacc.dao.sort;

import java.util.HashSet;
import java.util.Set;

import com.daacc.dao.teacher.Teacher;

public class Sort implements java.io.Serializable {

    // Fields

    private Integer id;

    private Integer parentId;

    private String name;

    private String description;

    private Set erratas=new HashSet();

    // Constructors

   
    public Sort() {
    }

   
    public Sort(Integer id) {
        this.id = id;
    }

   
    public Sort(Integer id, Integer parentid, String name, String description) {
        this.id = id;
        this.parentId = parentid;
        this.name = name;
        this.description = description;
        // this.teachers = teachers;
    }

    // Property accessors

    public Integer getId() {
        return this.id;
    }

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

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public Set getErratas() {
        return erratas;
    }

    public void setErratas(Set erratas) {
        this.erratas = erratas;
    }

    @Override
    public int hashCode() {
        final int PRIME = 31;
        int result = super.hashCode();
        result = PRIME * result + ((description == null) ? 0 : description.hashCode());
        result = PRIME * result + ((id == null) ? 0 : id.hashCode());
        result = PRIME * result + ((name == null) ? 0 : name.hashCode());
        result = PRIME * result + ((parentId == null) ? 0 : parentId.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (!super.equals(obj))
            return false;
        if (getClass() != obj.getClass())
            return false;
        final Sort other = (Sort) obj;
        if (description == null) {
            if (other.description != null)
                return false;
        } else if (!description.equals(other.description))
            return false;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        if (parentId == null) {
            if (other.parentId != null)
                return false;
        } else if (!parentId.equals(other.parentId))
            return false;
        return true;
    }

}
Sort.hbm.xml
<?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 - Hibernate Tools
-->

<hibernate-mapping>


    <class name="com.daacc.dao.sort.Sort" table="sort">
        <id name="id" type="integer">
            <column name="id" />
            <generator class="native" />
        </id>

        <property name="parentId" type="integer">
            <column name="parent_id" not-null="true" />
        </property>
        <property name="name" type="string">
            <column name="name" length="30" />
        </property>
        <property name="description" type="string">
            <column name="description" length="300" />
        </property>
        <set name="erratas" inverse="false" lazy="true"
            cascade="all-delete-orphan" outer-join="true">
            <key>
                <column name="sort_id" not-null="true" />
            </key>
            <one-to-many class="com.daacc.dao.errata.Errata" />
        </set>

    </class>

</hibernate-mapping>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值