其实单实体的一对多和多对一和2个实体的用法是一样的,现在以user为例:
java代码:
package com.test.bean;
import java.util.Set;
public class User
{
private Integer id;
private String firstname;
private String lastname;
private Integer parentID;
private int age;
private Set childrens;
private User user;
public Set getChildrens() {
return childrens;
}
public void setChildrens(Set childrens) {
this.childrens = childrens;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Integer getId()
{
return id;
}
public void setId(Integer id)
{
this.id = id;
}
public String getFirstname()
{
return firstname;
}
public void setFirstname(String firstname)
{
this.firstname = firstname;
}
public String getLastname()
{
return lastname;
}
public void setLastname(String lastname)
{
this.lastname = lastname;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public Integer getParentID() {
return parentID;
}
public void setParentID(Integer parentID) {
this.parentID = parentID;
}
}
对应的hbm文件:
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">