It´s is working!
Here is my class:
Code:
public class Menu {
private Long id;
private String title;
private String link;
private Menu parent;
private List<Menu> children;
public Menu() {
this(null, null);
}
public Menu(String title, String link) {
this.title = title;
this.link = link;
children = new ArrayList<Menu>();
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public Menu getParent() {
return parent;
}
public void setParent(Menu parent) {
this.parent = parent;
}
public void setChildren(List<Menu> children) {
this.children = children;
}
public List<Menu> getChildren() {
return children;
}
public void addChild(Menu menu) {
getChildren().add(menu);
menu.setParent(this);
}
}
Here is the hbm.xml:
Code:
<many-to-one name="parent"
column="ID_PARENT"
class="Menu" />
<bag name="children"
inverse="true"
cascade="all"
lazy="false">
<key column="ID_PARENT" />
<one-to-many class="Menu" />
</bag>
I love Hibernate!!
Hope it helps.