首页 > 解决方案 > Bean 方法关闭会话导致没有会话或会话已关闭异常

问题描述

我有基于 Java SEAM 的 cms。用户界面是基于 JSF 实现的,但有一个例外 - 一个子页面是使用带有 angualrJS 的纯 html 实现的。这个子页面通过这个类与 cms 通信:

@Name("editorv2Service")
@Path("/4854b417-6aea-4ed5-920e-f56083c21d68")
@Scope(ScopeType.SESSION)
public class Editorv2Service {
    @GET
    @Path("/editorv2json/accountMetaData")
    @Produces("application/json;charset=UTF-8")
    public Response getAccountMetaData() {
        ...some code...
    }  

    ... other methods...
}

我可以在 JSF 页面之间导航,我可以打开 AngualrJS 页面然后返回 JSF 页面等。一切正常,直到 AngualrJS 调用 getAccountMetaData。方法本身可以正常返回有效数据。问题是在调用该方法后导航到某个 JSF 页面会导致以下异常:

/templates/system/layout/common/pagebegining.xhtml @68,76 test="#{!addModulePermission and identity.hasRole('TRIAL')}" Permissions.Rule_CheckModules_0Eval0Invoker@aeeb6e23 : org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: pl.ceferty.cms.entity.portal.Portal.sections, no session or session was closed

看起来调用 Editorv2Service 的任何方法都会关闭 Hibernate 会话。用户会话没有关闭——我仍然可以访问一些 JSF 页面。

它看起来像 SEAM 中的一个错误。有解决方案或解决方法吗?

我已经阅读了所有描述类似问题的答案,但对我没有任何帮助。


可以说我有这样定义的对象:

@Entity
@Table(name = "view", uniqueConstraints = { @UniqueConstraint(columnNames = { "address", "portal_id" }) })
@NamedQueries({ @NamedQuery(name = "view.byId", query = "from View v where v.id = :viewId", cacheable = true),
    @NamedQuery(name = "view.byAddress", query = "from View v where v.address = :address", cacheable = true),
    @NamedQuery(name = "view.addressAvailable", query = "select count(distinct v) from View v where v.address=:address") })
public class View extends pl.ceferty.cms.entity.base.CMSEntity
... implementation ...

我使用以下方法在端点中访问此对象:

View view = (View) Component.getInstance("cfview", true);

如何将此对象合并到会话?

标签: hibernatejsfseamjboss-seam

解决方案


推荐阅读