Hibernate get对象的懒加载问题

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.wolf.a_StudentManageSystem.domain.Teacher.courses, could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:575)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:214)
at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:554)
at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:142)
at org.hibernate.collection.internal.PersistentSet.toString(PersistentSet.java:316)
at java.lang.String.valueOf(String.java:2854)
at java.lang.StringBuilder.append(StringBuilder.java:128)
at com.wolf.a_StudentManageSystem.domain.Teacher.toString(Teacher.java:28)
at java.lang.String.valueOf(String.java:2854)
at java.io.PrintStream.println(PrintStream.java:821)
at com.wolf.a_StudentManageSystem.DaoImpl.TeacherDaoImplTest.testGetById(TeacherDaoImplTest.java:35)

懒加载问题:
Hibernate在get对象时,如果含有集合或者实体,会懒加载。
可以在集合的属性配置里,设置 lazy="false",或者实体类属性配置为lazy="false"。






郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。