@Entity设置OneToMany

Hibernate设置bean映射数据库的方式有配置模式与注解模式,下面通过注解模式配置OneToMany

@Entity
@Table(name="csdnbbs_sys_catalog")
@org.hibernate.annotations.Proxy(lazy = false)
public class Catalog {

private Catalog parent ;
        
private String  id ;
private String  name ;
private String  url ;


private Set<Catalog> children = new HashSet<Catalog>();


@OneToMany(cascade=CascadeType.ALL, mappedBy="parent")
        public Set<Catalog> getChildren() {
return children;
}
public void setChildren(Set<Catalog> children) {
this.children = children;
}

}

鸣谢:http://bbs.csdn.net/topics/390522138

原文地址:https://www.cnblogs.com/wql025/p/4817494.html