首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sakai Hibernate延迟初始化

Sakai Hibernate延迟初始化
EN

Stack Overflow用户
提问于 2014-08-28 03:55:24
回答 1查看 60关注 0票数 0

我在构建数据库时遇到了一些问题。我有这两个hbm映射:

代码语言:javascript
复制
<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集合失败,没有会话或会话被关闭

EN

回答 1

Stack Overflow用户

发布于 2014-09-03 09:52:43

我们需要查看

代码语言:javascript
复制
List modules = new ArrayList(dao.findById(Course.class, course).getCourseModules())

是否在dao.findById方法中打开和关闭会话(或EntityManager)?会话必须仍处于打开状态才能解决惰性关系

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25535889

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档