且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么要使用有状态会话bean?

更新时间:2023-12-03 16:04:52


I'm learning ejb3 and I'm just curious when it's convinient to use SFSB? I can't find any nice example when SFSB realy solve easily some complex problem.

你的意思是购物车?这是我能想到的明显答案。

You mean like a shopping cart? That's the obvious answer that I can think of.


实际上我看到SLSB可以用作网络服务,这很方便。

Actually I see that SLSB can be used as web-services and this is convenient.

您可以将EJB视为部署分布式服务的一种方式,但要小心。术语Web服务使大多数人想到使用HTTP协议的基于SOAP的Web服务,而这不是您在SFSB中所拥有的。

You can think of EJBs as one way to deploy distributed services, but be careful. The term "web services" makes most people think of "SOAP-based web services using HTTP protocol", and that's not what you have in a SFSB.


但我不知道何时使用SFSB。我只看到它的问题,因为我们应该学习一些东西,我们应该编写一个由注释组成的代码,然后完全使用,我们应该使用讨厌的查找。我们不会得到任何好的回报。

But I don't know when to use SFSB. I see only problems with it because we should learn something about it, we should write code which consists of annotations a bit less then completely, we should use annoying lookup.. And we don't get anything good in return.

这一段令人困惑,但我认为你说你不太喜欢EJB。

This paragraph is confusing, but I think you're saying you don't like EJBs much.


例如,我们不能使用SLSB中的SFSB,因为有状态对象只能用于有状态上下文。

For example, we can't use SFSB from SLSB because stateful objects can be used only from stateful context.

对,它们是互补的。您将SFSB用于需要的用例 - 等待它 - 在调用之间保持状态。

Right, they're complementary. You use SFSB for use cases that require - wait for it - state to be maintained between calls.


我们不能在servlet中使用DI而不是它我们应该使用查找手动创建SFSB实例,然后将其放到HttpSession对象。它不能是网络服务。

We can't use DI in servlets, instead of it we should manually create SFSB instance using lookup and then put it to HttpSession object. It can't be a web-service.

servlet来自哪里?

Where did servlets come from here?


我在SFSB中看到的唯一利润是交易管理。但我认为这种情况很少见,因为我们真的需要一个交易,而且我们不需要DB。我可以假设,当我们将数据存储在xml文件中并在SFSB中使用事务管理来模拟非关系数据库时,它可能非常有用。

The only profit I can see in SFSB is a transaction management. But I think it's rare case when we really need a transaction and we don't need DB. I can suppose that it can be realy useful when we store our data in xml-file and use transaction management in SFSB to simulate nonrelational DB.



I think you're totally off base here. Sessions beans are the ones that know about units of work and managing transactions. They probably have to work with entity beans to persist some of that state when the use case is done, so transactions aren't as uncommon as you seem to think.


我几乎可以肯定我完全错了,所以给我一些很好的SFSB使用示例。

I'm almost sure that I'm totally wrong, so give me some realy nice examples of SFSB usage.



What's your expectation? That someone will post working SFSB? I'm not going to do that, mostly because I'm not a big EJB fan. (I do everything you're alluding to and more with Spring.)

但请放心,SFSB有时很有用。购物车就是一个明显的例子。在客户决定购买之前,您需要一个位置来维护购物车中的商品。 SFSB是实现这一目标的一种方式。

But rest assured that SFSB are sometimes useful. The shopping cart is the obvious example. You need a place to maintain items in the cart until the customer decides to purchase. SFSB is one way to accomplish that.