分享

Hibernate树型结构的算法,附源码!

 smoking_boy 2006-06-13
/**
* @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;
        }
       
        /**
        * 获得父节点
        * @hibernate.many-to-one
        *  column="parentId"
        */

        public Component getParent(){
                return parent;
        }
       
        public void setParent(Component parent){
                this.parent=parent;
        }
       
        /**
        * 获得子节点
        * @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();
        }
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多