質問

Stateful session beans are often illustrated by implementing a shopping cart. Coming from outside Java EE, my inclination would be to handle this kind of state with a persistent model entity: a ShoppingCart object with Products and quantities. This way, my state is being maintained by the database along with all my other state rather than by the application server.

What are the technical advantages to stateful session bean design over "ordinary" persistence? Are shopping carts in Java EE-based web applications indeed usually written with SFSBs, or as in other systems just by more elaborate domain modeling?

役に立ちましたか?

解決

There are several ways to implement a shopping cart. The main difference between SFSB and DB persistence is, well, the persistence :)

A Stateful session bean will only "persist" the data during the session time. So if the user session becomes inactive (for exemple after 30 minutes of inactivity), the shopping cart will be reset

With the database persistence, the shopping cart will be stored permenantly, so if a user have a filled shopping cart, then don't visit the webshop during 6 months, and visit it again, the cart will still be filled

I think usually the first solution is used, as involving a non in-memory database is not a good idea to store volatile data. There will be a lot of hard drive I/O overhead for data that don't really need long-term persistence

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top