It's been ages since I've last used EJB's so I'm kind of lost here. The question is, how should one approach the need to maintain a collection of EntityBeans?
Here's a scenario, a classical online shop:
- Users can add items to a shopping cart - The shopping cart should not be persisted into a database - The items themselves are of a single type of EntityBean
Now, I suppose this could be handled using CMR if the shopping carts would be EntityBeans as well, but what would be a good way to handle this with the ShoppingCart being a Stateful SessionBean, for example? How about if the shopping cart is just a POJO (a java.util.Vector, for example)?
Just for aesthetic reasons, if you're using EJBs for the items in a shopping cart, you might as well be consistent and use an EJB shopping cart as well. If nothing else, it'll probably help in maintainability because you're usig a consistent code model.
I doubt that as your project progresses you'll want to keep the cart as a simple vector, anyway. Usually as you progress through checkout, you'll be accumulating additional shipping, ordering and billing info. So at that point you'll become a complex custom class regardless.
An IDE is no substitute for an Intelligent Developer.
Joined: Mar 06, 2001
Originally posted by Lasse Koskela:
Ah. But isn't this an EntityBean-has-EntityBeans situation? What if I don't want that? What if I want a non-persistent object to have a collection of EntityBeans?
ok. I'm not sure if i got your question. Tell me this, when you fetch the item beans in the first place for display, guess you already have value objects for those. Depending upon what the customer adds to the shopping cart, you will add them to a vector of item value objects and hold them as instance variable in your StatefulSession bean shopping cart right?
Later when you persist, you will persist them in a Customer-Items table / whichever way you track an order, looking up those ItemBeanLocals and CustomerLocal?
Joined: Jan 23, 2002
Originally posted by Karthik Guru: Tell me this, when you fetch the item beans in the first place for display, guess you already have value objects for those. Depending upon what the customer adds to the shopping cart, you will add them to a vector of item value objects and hold them as instance variable in your StatefulSession bean shopping cart right?
Yep. That's how I probably would do it. This "what if" stuff is for purely self-educational purposes. I don't have a project that actually requires this stuff -- I'm just trying to update my world view about EJB's after a rather long period of not having to deal with them beasts