org.hibernate.LazyInitializationException: could not initialize proxy - no Session
程序员文章站
2022-04-17 22:37:47
...
初始化的时候session关闭了,这个主要是因为hibernate默认的懒加载策略:默认lazy为true 引起的异常
。
1、配置文件加上
#lazy=false
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
2、在实体类加上
@Entity
@Proxy(lazy = false) ------//关闭懒加载
@Table(name="category")
@JsonIgnoreProperties(value = { "hibernateLazyInitializer"})
public class Category {
推荐阅读
-
could not initialize proxy - no Session
-
解决:org.hibernate.LazyInitializationException: could not initialize proxy - no Session
-
HTTP Status 500 - Could not write content: could not initialize proxy - no Session
-
could not initialize proxy - no Session:解决懒加载(排除不需要查询显示的属性)
-
org.hibernate.LazyInitializationException: could not initialize proxy [xxxx] - no Session异常
-
Hiberante异常之org.hibernate.LazyInitializationException: could not initialize proxy - no Session
-
【记录】异常:org.hibernate.LazyInitializationException: could not initialize proxy - no Session
-
org.hibernate.LazyInitializationException: could not initialize proxy 解决方案(JPA)
-
Jpa项目报错:org.hibernate.lazyinitializationexception could not initialize proxy - no session
-
org.hibernate.LazyInitializationException: could not initialize proxy no Session