我在构建数据库时遇到了一些问题。我有这两个hbm映射:
<class name="br.unicamp.iel.model.Module" table="readinweb_modules">
<id name="id" type="java.lang.Long">
<generator class="increment" />
</id>
<many-to-one name="course" class="br.unicamp.iel.model.Course"
column="course_id" fetch="select" />
<property name="position" type="integer" />
<property name="module_grammar" type="text" />
</class>
<class name="br.unicamp.iel.model.Course" table="readinweb_courses">
<id name="id" type="java.lang.Long">
<generator class="increment" />
</id>
<property name="title" length="255" not-null="true" type="string" />
<property name="idiom" length="255" not-null="true" type="string" />
<property name="description" type="text" />
<set name="courseModules" table="readinweb_modules"
inverse="true" lazy="true" fetch="select">
<key column="id" not-null="true" />
<one-to-many class="br.unicamp.iel.model.Module" />
</set>
</class>当我尝试访问我的逻辑bean上的数据时: List modules = new ArrayList(dao.findById(Course.class,course).getCourseModules());
它给了我一个角色:懒惰地初始化org.hibernate.LazyInitializationException: br.unicamp.iel.model.Course.courseModules集合失败,没有会话或会话被关闭
发布于 2014-09-03 09:52:43
我们需要查看
List modules = new ArrayList(dao.findById(Course.class, course).getCourseModules())是否在dao.findById方法中打开和关闭会话(或EntityManager)?会话必须仍处于打开状态才能解决惰性关系
https://stackoverflow.com/questions/25535889
复制相似问题