Jpa 非法访问加载集合(hibernate.LazyInitializationException)
我正在使用JPA和Hibernate持久性提供程序 我有一对多映射,我用Jpa 非法访问加载集合(hibernate.LazyInitializationException),jpa,Jpa,我正在使用JPA和Hibernate持久性提供程序 我有一对多映射,我用 @OneToMany(mappedBy = "mSearchPreference", cascade = CascadeType.ALL, fetch=FetchType.EAGER) 我可以在控制台上看到一对多SQL语句,即使我遇到异常 illegal access to loading collection (hibernate.LazyInitializationException) org.hibernate.
@OneToMany(mappedBy = "mSearchPreference", cascade = CascadeType.ALL, fetch=FetchType.EAGER)
我可以在控制台上看到一对多SQL语句,即使我遇到异常
illegal access to loading collection (hibernate.LazyInitializationException)
org.hibernate.LazyInitializationException: illegal access to loading collection
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:341)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.AbstractPersistentCollection.readElementExistence(AbstractPersistentCollection.java:142)
at org.hibernate.collection.PersistentSet.add(PersistentSet.java:187)
有人能帮我做些什么其他安排吗?这通常意味着在尝试访问新实体时,Hibernate会话已经关闭。解决此问题的两个选项是:
- 查看所有模型图,并在需要时设置适当的急取类型
- 设置扩展的持久性内容:@PersistenceContext(type=PersistenceContextType.extended)