org.hibernate.LazyInitializationException:无法初始化代理 - 没有会话

时间:2014-02-06 11:52:22

标签: java hibernate

我使用的是jsf 2.2.4,ejb3和hibernate4。

我有两个实体,一个是SecTblPermission,另一个是SecTblMenu。

当我通过例外获得权限时:

Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
    at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:149) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:195) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
    at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
    at com.server.myapp.ifin.model.SecTblMenu_$$_javassist_21.getSecTblMenu(SecTblMenu_$$_javassist_21.java) [classes:]
    at com.web.myapp.ifin.sec.config.controller.LoginController.getGroupPermissions(LoginController.java:216) [classes:]
    at com.web.myapp.ifin.sec.config.controller.LoginController.login(LoginController.java:173) [classes:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_40]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_40]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_40]
    at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_40]
    at org.apache.el.parser.AstValue.invoke(AstValue.java:262) [jbossweb-7.0.13.Final.jar:]
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) [jbossweb-7.0.13.Final.jar:]
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.2.1.jar:2.2.1-SNAPSHOT]
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) [jsf-api-2.2.1.jar:2.2]
    ... 21 more

我的hql是;

select permission from SecTblPermission as permission left join permission.secTblMenu as menu where menu.secTblMenu.serMenuId is not null and permission.secTblCompany.serCompanyId='1' and permission.secTblBranch.serBranchId='1' and permission.secTblGroups.serGroupId IN(select group.secTblGroups.serGroupId from SecTblGroupsUsers group where group.secTblUsers.serUserId=1) order by menu.numMainMenuSequenceNo,menu.numSubMenuSequenceNo

请任何人帮助我为什么会这样?

0 个答案:

没有答案