In fact, the usage of one-to-many and many-to-one of a single entity is the same as that of 2 entities. Now take user as an example:
java code:
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;
}
}
Corresponding hbm file:
"http://hibernate .sourceforge.net/hibernate-mapping-3.0.dtd">