vinegardou 2011-10-12 16:26 采纳率: 0%
浏览 210
已采纳

大家帮我看看这个异常信息

Exception in thread "Main Thread" org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: cn.com.obj.model.po.std.SysRole.rights, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:122)
at org.hibernate.collection.PersistentBag.size(PersistentBag.java:248)
at test.PermissionTest.main(PermissionTest.java:17)

测试:
public class PermissionTest {
public static void main(String[] args) {
ApplicationContext act=new FileSystemXmlApplicationContext("classpath:cn/com/myweb/spring/applicationContext.xml");
IUserInfoBiz userInfoBiz=(IUserInfoBiz) act.getBean("userInfoBiz");
List users=userInfoBiz.userInfoList();
System.err.println(users.size());
System.err.println(users.get(0).getRole().getRights().size());
}
}

hb.xml文件:
userinfo:









    <many-to-one name="role" class="SysRole" fetch="select" lazy="false">
        <column name="roleID" not-null="true"></column>
    </many-to-one>
 </class>

SysRole:









    <!-- 
     -->
    <bag name="rights" inverse="true" table="sys_role_right">
        <key>
            <column name="roleID" not-null="true"/>
        </key>
        <many-to-many entity-name="cn.com.obj.model.po.std.SysRight">
            <column name="rightID" not-null="true"></column>
        </many-to-many>
    </bag>

    <bag name="users" inverse="true">
        <key>
            <column name="roleID" not-null="true"></column>
        </key>
        <one-to-many class="UserInfo"/>
    </bag>
 </class>

SysRight:


















 </class>

  • 写回答

1条回答 默认 最新

  • AngelAndAngel 2011-10-12 16:31
    关注


    这个里面加上 lazy=false

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况