码迷,mamicode.com
首页 > Web开发 > 详细

Hibernate get对象的懒加载问题

时间:2015-04-20 22:12:20      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

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"。






Hibernate get对象的懒加载问题

标签:

原文地址:http://www.cnblogs.com/homer3000/p/4442530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!