我正在使用JPA与Hibernate持久性提供程序.
我用了一对多的映射
@OneToMany(mappedBy = "mSearchPreference", cascade = CascadeType.ALL, fetch=FetchType.EAGER)
Run Code Online (Sandbox Code Playgroud)
我可以在控制台上看到一对多的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)
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决我需要做的其他安排吗?
这通常意味着在尝试访问新实体时 Hibernate 会话已经关闭。解决此问题的两个选项是:
| 归档时间: |
|
| 查看次数: |
9115 次 |
| 最近记录: |