public Integer getId() {
return id;
}
public void setId(Integer id) {
thisid = id;
}
@Override
public int hashCode() {
int hash = ;
hash += (id != null ? idhashCode() : );
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning this method wont work in the case the id fields are not set
if (!(object instanceof Person)) {
return false;
}
Person other = (Person) object;
if ((thisid == null && otherid != null) || (thisid != null && !thisidequals(otherid))) {
return false;
}
return true;
}
@Override
public String toString() {
return comhadesleejpaentityPerson[id= + id + ];
}
}
由于JPA是不需要配置的代码里面已经包括了注释所以下面附上Hibernate的映射文件为了使数据库里面更清楚一些所以两者使用的表不是同一张表JPA的表是带JPA前缀的用@Table这个注释声明了这一点
<?xml version= encoding=UTF?>
<!DOCTYPE hibernatemapping PUBLIC
//Hibernate/Hibernate Mapping DTD //EN
http://hibernatesourceforgenet/hibernatemappingdtd>
<hibernatemapping package=comhadesleejpaentity>
<class name=Department table=Department>
<id name=id column=departId type=long>
<generator class=native/>
</id>
<property name=deptName/>
<property name=description/>
<set name=persons>
<key column=deptId/>
<onetomany class=Person/>
</set>
</class>
<class name=Person table=Person>
<id name=id column=personId type=long>
<generator class=native/>
</id>
<property name=name/>
<property name=age/>
<manytoone name=department column=deptId class=Department/>
</class>
</hibernatemapping>
[] [] [] [] []