从无状态Bean返回状态Java Bean? [英] Returning a Stateful Java Bean from a Stateless Bean?
问题描述
我想处理登录方式如下:
I want to handle a login scenario as follows:
- 客户端连接到无状态Java Bean(SLJB)并尝试登录;
- 如果登录成功,SLJB向用户返回状态Java Bean(SFJB),以便客户端可以继续使用应用程序。
我目前正在做第二步:
return new StatefulBean(some params);
这是正确的方法吗?对我来说似乎不符合我的例外:
Is this the right way to do it? It does not seem to me as I get the exception:
Class org.eclipse.persistence.internal.jpa.EntityManagerImpl is not Serializable
当我运行我的应用程序,我认为它与描述的方法有关。
when running my application, and I think it is related to the described method.
从SLJB向客户端返回SFJB引用的正确方法是什么?
What would be the correct way to return a reference to the SFJB from the SLJB to the client?
推荐答案
首先,这是完全错误的:
First of all, this is completely wrong:
new StatefulBean(some params)
EJB容器负责创建和销毁bean的实例,您不应该手动创建它们。
EJB container is responsible for creating and destroying instances of beans, you should never create them manually.
在您的情况下,我将逆转流程:客户端连接到有状态的bean,这可能是无状态会话bean作为助手。不需要传递bean,客户端始终使用同一个bean。
In your scenario I would reverse the flow: the client connects to the stateful bean which might stateless session bean as a helper. No need to pass beans around, client always uses the same bean.
这篇关于从无状态Bean返回状态Java Bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!