1

When I create a cart shopping bean in Spring MVC , it's better to save it into a table of a database or put the bean in session?I'm no expert and I would like your opinion about it. Thanks

Alex
  • 2,075
  • 5
  • 27
  • 39

2 Answers2

1

You should use the session to save the cart, as the client may or may not finally buy the product, this way you won't waste time and space doing transactions.

Luke SpringWalker
  • 1,600
  • 3
  • 19
  • 33
  • but when the session is expired i lost all my articles. If I save the cart in a database I don't lost anything – Alex Nov 27 '14 at 20:38
  • You can reforce that with the cookies. Also, image all the transactions that would be made if you save all the carts of all clients. – Luke SpringWalker Nov 27 '14 at 20:40
  • If you check, for example, ebay, you may find that they store the cart en their databases, but the proccesing power and storage they have is huge. – Luke SpringWalker Nov 27 '14 at 20:43
  • my teacher says that it's better to persist the cart in a database and he says that all the web sites do it. Is He saying the false? – Alex Nov 27 '14 at 20:44
  • He is not saying false, big companies can afford that, but it's not a good choice if you have limited resources. – Luke SpringWalker Nov 27 '14 at 20:45
  • But if i want to persist the cart, how can I proceed?I save it first in the session and when the session expired i save it into the database?Can I use the cookie also? – Alex Nov 27 '14 at 20:52
  • You should trigger the actions when the session expires or is closed, this way you just persist one time per session. You could use cookies too. – Luke SpringWalker Nov 27 '14 at 20:55
  • Can you suggest some guidelines ,on the web,to follow? – Alex Nov 27 '14 at 20:58
  • It depends on what technology you are using, for example, in spring you could have this approach http://stackoverflow.com/questions/11843010/logout-session-timeout-catching-with-spring-security – Luke SpringWalker Nov 27 '14 at 20:59
1

It's better to keep it in Session. If you keep it in database and user does not finish actions. For instance, if application crashed, you'll have it in database. I don't think it's want you want.

Pracede
  • 4,226
  • 16
  • 65
  • 110
  • my teacher says that it's better to persist the cart in a database and he says that all the web sites do it. Is He saying the false? – Alex Nov 27 '14 at 20:42