处理'EJB不存在'或'无法从BACKUPSTORE FOR Key加载' [英] Handling 'The EJB does not exist' or 'Cannot load from BACKUPSTORE FOR Key'

查看:195
本文介绍了处理'EJB不存在'或'无法从BACKUPSTORE FOR Key加载'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以问题很简单:



我们正在使用带有Primefaces和EJB的JSF 2.0来处理我们的应用程序,我们遇到了一个问题。我们有一个 @SessionScoped bean,其中我们存储我们所有的 @Stateful Session Bean



在一种情况下(当我们没有处理JPA的一些例外),并且有一个例外:

  javax.persistence.PersistenceException:异常[EclipseLink-4002](Eclipse Persistence Services  -  2.2.0.v20110202-r8913):org.eclipse.persistence.exceptions.DatabaseException 
内部异常:org.postgresql .util.PSQLException:ERROR:重复键值违反唯一约束webuser_idwebuser_pk
详细信息:Key(idwebuser)=(6)已存在。

它导致我们的一个 @Stateful Session Bean
所以在刷新网站后,当JSF仍然正常工作时,填写表单并尝试提交后,通过调用该Bean中的一个方法,就会有一个例外:

  javax.ejb.NoSuchObjectLocalException:EJB不存在。会话密钥:22900a4d007e1f-6dcc714a-0 

最有问题的是我们必须重新启动并重新部署该应用程序使其在同一台计算机(或Web浏览器)上工作,因为JSF的 @SessionScoped Bean以某种方式通过Cookie或某些东西进行保存。



所以我想的解决方案是强制摧毁那个 @SessionScoped 或刷新会话不知何故,但实际上我不知道该怎么做所以。
或者什么是更好的方法。



谢谢!

解决方案>

好吧,我自己找到了答案。
实际上,我需要的是通过扩展ActionListenerImpl来处理JSF视图中的异常。



原始文章在这里:
原始



但是我所做的是通过使HTTP会话无效来扩展异常处理,最终结束了code> @SessionScoped Managed Bean的使用寿命,并导致重新插入SSB。像这样:

  private void gotoErrorPage(MethodExpression expression){
FacesContext context = FacesContext.getCurrentInstance();
应用程序应用程序= context.getApplication();

HttpSession session =(HttpSession)FacesContext.getCurrentInstance()。getExternalContext()。getSession(false);
if(session!= null){
session.invalidate();
}

NavigationHandler navHandler = application.getNavigationHandler();
navHandler.handleNavigation(context,null == expression?null:expression.getExpressionString(),NAV_ERRORPAGE);
context.renderResponse();
}


so the problem is pretty simple:

We are using JSF 2.0 with Primefaces and EJB to handle our application and we have encountered a problem. We have a single @SessionScoped bean in which we store all ours @Stateful Session Beans.

In one case, (when we didn't handle some exceptions from JPA) and there is an exception:

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "webuser_idwebuser_pk"
  Detail: Key (idwebuser)=(6) already exists.

It leads to destruction of one of our @Stateful Session Bean. So after refreshing the website, when JSF is still working correctly, after filling the form and trying to submit it, by invoking a method from that Bean there is an exception:

javax.ejb.NoSuchObjectLocalException: The EJB does not exist. session-key: 22900a4d007e1f-6dcc714a-0

What is the most problematic, we have to restart and redeploy the application to make it work on the same computer (or web browser) because the JSF's @SessionScoped Bean is somehow kept through cookies or something.

So the solution I guess would be to force the destuction of that @SessionScoped or refresh the session somehow, but actually I have no idea how to do so. Or what would be a better approach.

Thanks!

解决方案

Ok so I've found the answer on my own. Actually what I've needed was to handle exceptions in JSF view by extending ActionListenerImpl.

The original article is here: Original

But what I've done was to extend the exception handling with invalidating the HTTP session which, in the end, ended the life of @SessionScoped Managed Bean and leaded to reinjection of SSBs. Like this:

private void gotoErrorPage(MethodExpression expression) {
        FacesContext context = FacesContext.getCurrentInstance();
        Application application = context.getApplication();

        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        if (session != null) {
            session.invalidate();
        }

        NavigationHandler navHandler = application.getNavigationHandler();
        navHandler.handleNavigation(context, null == expression ? null : expression.getExpressionString(), NAV_ERRORPAGE);
        context.renderResponse();
    }

这篇关于处理'EJB不存在'或'无法从BACKUPSTORE FOR Key加载'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆