种类Sort与勘误Errata是一对多的关系.
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>