hibernate lazy=false annotation设置

工程报错如下:

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

解决方法:

在类的头部加上@org.hibernate.annotations.Proxy(lazy = false)

@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;
}

  

原文地址:https://www.cnblogs.com/toSeeMyDream/p/4514417.html