Last post Nov 17, 2010 02:34 PM by sachingusain
Nov 15, 2010 03:26 AM|liuc|LINK
hi, this is a newbie calling for help.
how do you treat situations where there is the need of storing collections of object belonging to an object not persisted on db (not yet).
For example , suppose we have a web application for submitting orders.
The user click on 'Create new order" , then insert order's data , choose items from a catalog and add them to the order. Finally he "submit" the order.
I can see two different way to persiste data :
a) create on db an empty order instance when user click on "create new order" , so that the orderitems collection could be directly associated (saved) with that instance in the db.
b) keep all data in memory and finally save order and orderitem.
The b option imply storing (in session?) the orderitems collection till submit.
Are there, probably, other solutions. Which are best practices in these situation?
thank you very much.
Nov 15, 2010 04:18 AM|Deeshal|LINK
Nov 15, 2010 06:05 AM|liuc|LINK
Should i serialize the items collection into cookies?
Nov 17, 2010 11:48 AM|nikshukla|LINK
Do you need to populate not submitted order data if user leaves site without submitting it and comes back 2 days later?
If so best thing to do is create physical temp table in your database with exact same schema as your final order table.
This temp table will hold data for all not yet submitted orders. Once order is submitted you can delete record from temp table or you can create your own clean up process which deletes data based on some criteria.
Nov 17, 2010 02:34 PM|sachingusain|LINK
I would suggest going with session objects and persisting the order information there. (unless there is a requirement to come back some days later - as mentioned by @nikshukla).
Cookies too can be done but remember, some users might have disabled it.