【org.hibernate.LazyInitializationException: failed to lazily initialize】问题解决

报错:
org.hibernate.LazyInitializationException: failed to lazily initialize XXXXX could not initialize proxy - no Session

【org.hibernate.LazyInitializationException: failed to lazily initialize】问题解决_第1张图片
解决:
这个问题是由于实体中一对多或者多对多关联关系的加载方式配置不当引起的。
一对多或者多对多关联关系的加载策略使用了懒加载,结果在加载子实体时就会报 org.hibernate.LazyInitializationException: failed to lazily initialize XXXXX could not initialize proxy - no Session错误,只需要将懒加载改为急加载即可

懒加载:

@OneToMany(cascade = CascadeType.ALL, targetEntity = MetaTableJoinColumn.class, mappedBy = "metaTableJoin", fetch = FetchType.LAZY)


急加载:
@OneToMany(cascade = CascadeType.ALL, targetEntity = MetaTableJoinColumn.class, mappedBy = "metaTableJoin", fetch = FetchType.EAGER)

你可能感兴趣的:(问题解决,Java)