/** * @hibernate.class * table="tree" */ public class Component { private long id; private String name; private Component parent; private Set children=new HashSet(); private Component(){} public Component(String name){ this.name=name; } /** * @hibernate.id * generator-class = "native" */ public getId(){ return Id; } private setId(long id){ this.id=id; } /** * @hibernate.property * length="64" * not-null="true" */ public String getName(){ return name; } public void setName(String name){ this.name=name; } /** * 獲得父節(jié)點(diǎn) * @hibernate.many-to-one * column="parentId" */ public Component getParent(){ return parent; } public void setParent(Component parent){ this.parent=parent; } /** * 獲得子節(jié)點(diǎn) * @hibernate.set * lazy = "true" * table = "tree" * @hibernate.collection-key * column = "parentId" * @hibernate.collection-one-to-many * class = "Component" */ public Set getChildren(){ return children; } private void setChildren(Set children){ this.children=children; } public void addChild(Component child){ children.add(child); } public void removeChild(Component child){ childrent.remove(child); } public void clearChildren(){ children=new HashSet(); } } |
|