开发者社区> 问答> 正文

Hibernate懒加载出现问题: LazyInitializationExce?报错

clazz------student   1对多的关系

现在通过获取student对象后,再去懒加载获取clazz对象报错:
org.hibernate.LazyInitializationException Cannot evaluate com.framework.util.core.entity.onetomany.ClazzEntity_$$_javassist_5.toString()

@Entity
@Table(name = "clazz")
public class ClazzEntity extends BaseEntity {

    private String name;
    private String clazzNo;
    List<StudentEntity> studentEntityList;

    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "clazzNo")
    public String getClazzNo() {
        return clazzNo;
    }

    public void setClazzNo(String clazzNo) {
        this.clazzNo = clazzNo;
    }

    @OneToMany(mappedBy = "clazzEntity",cascade = CascadeType.ALL)
    public List<StudentEntity> getStudentEntityList() {
        return studentEntityList;
    }

    public void setStudentEntityList(List<StudentEntity> studentEntityList) {
        this.studentEntityList = studentEntityList;
    }
}



@Entity
@Table(name = "student")
public class StudentEntity extends BaseEntity {


    private String name;
    private String studentNo;
    private ClazzEntity clazzEntity;

    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "studentNo")
    public String getStudentNo() {
        return studentNo;
    }

    public void setStudentNo(String studentNo) {
        this.studentNo = studentNo;
    }

    @ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    public ClazzEntity getClazzEntity() {
        return clazzEntity;
    }

    public void setClazzEntity(ClazzEntity clazzEntity) {
        this.clazzEntity = clazzEntity;
    }



请教下是什么原因?

展开
收起
爱吃鱼的程序员 2020-06-09 11:38:08 367 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    manytoone的级联关了none试了下,没用

    楼主解决了吗?我也出现相同问题,求解

    2020-06-09 11:38:25
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载