My general question is in a MVC patterned web app, what is the preferred way to scope and then update a bean after a request? I see 3 primary ways to go about it:
1) When the model is initially loaded, store it as a bean in the session. The user makes changes in the view, sends request. The controller grabs the bean from the session and from the request gets all the parameters that have new bean data, updates the bean with it's setters, sends the bean to the service layer to be saved.
2) Rebuild the bean from scratch only with request data: Model is initially loaded, bean is request scoped, and the view puts the beanID into one of its form fields (along with all other relevant bean properties), user changes data and sends request, controller gets the bean's id and all bean properties to be updated from the request and then builds a new bean from these and sends this object to the service to be saved.
3) same as #2 but after the request, controller makes 1 call to service layer with just the beanID that returns a complete bean that is an unaltered state, update the bean with the parameters retrieved from the request, send the updated bean back to the service layer for saving.
I want to use the first option because it seems like the easiest to implement and would be less taxing on the database. The second option would have less concurrency problems but it seems clunky to have to rebuild the bean from scratch, especially if there are bean properties that aren't relevant for this view that I would have to put in hidden fields so I could rebuild it accurately. The third options seems like overkill but thorough.
The details of the site in question: I am building a Java web app and trying to follow the MVC pattern. The basic functionality of the app is for managers to create plans for helping employees accomplish mutually agreed upon goals. The plan will contain different stages involved in accomplishing the overall goal and each stage will have specific tasks for completing the stage (so tasks are nested in stages which are nested in a plan). So the manager will build a "plan" and deploy it to the employee. Then the employee signs in, logs activity and marks task complete as he/she finishes them. The manager may occasionally modify the employees plan but the idea is that they would be collaborating on any changes to the plan after it was deployed. The manager can also run analytics on the employees data but that wouldn't actually change the employees data or the structure of the plan.
So, given that the employee is almost always going to be the only one who is accessing the data for his/her plans, I do not anticipate many issues where more than 1 person will be accessing data at the same time. That being said, I don't want to limit the site from growing should the requirements change and need more thread safety. I also want to use good coding practices to make it easier for others to improve and maintain the site.
Thanks for any feedback. I this is the largest scale project I've done to date so am seeing a lot of these problems for the first time.
Some of the research I've done:
how to choose the right bean scope