Ok, now I understand your problem.
In fact that is by design. The name instance that is passed to controller method is created from the request parameters, the process is called binding. So if your form doesn't contain middle field it has no way to appear in the name parameter passed to controller. The key point here is that it has nothing to do with your DAO.
Let's have a good look at your particular example. Pretend you have a Name stored in the DB with id = 1, name = Samuel, middle = Langhorne and last = Clemens. Let's also pretend that you have two user roles: ROLE_A can change name and middle, ROLE_B can change name and last.
First this to do is to display relevant fields for the form depending on user role:
HTML Code:
<form target="_self" enctype="application/x-www-form-urlencoded" action="changeName.vm" method="post">
<span>Full Name</span>
#springBind("name.first")
<label for="name.first">First Name: </label>
#springFormInput("name.first", "")
#if($security.AllGranted("ROLE_A"))
#springBind("name.middle")
<label for="name.middle">Middle Name: </label>
#springFormInput("name.middle", "")
#end
#if($security.AllGranted("ROLE_B"))
#springBind("name.last")
<label for="name.last">Last Name: </label>
#springFormInput("name.last", "")
#end
</form>
See these posts for how to get $security available in your templates. Note, I haven't tried it myself, but it should work
.
Now you need to obtain the Name stored in the DB using the submitted id (1), update properties allowed depending on roles current user is (2) (since nothing prevents him from POSTing fields not shown in markup, never trust the user
) and then save it back to the db (3).
Code:
@RequestMapping
public ModelAndView nameModification(Name name, BindingResult result) {
Name originalName = nameDao.getById(name.getId()); // (1)
// TODO: Handle missing DB entry somehow
boolean hasRoleA = false;
boolean hasRoleB = false;
for (GrantedAuthority authority : SecurityContextHolder.getContext().getAuthentication().getAuthorities()) { // (2)
if (authority.getAuthority().equals("ROLE_A")) {
hasRoleA = true;
} else if (authority.getAuthority().equals("ROLE_A")) {
hasRoleB = true;
}
}
originalName.setName(name.getName());
if (hasRoleA) { // (2)
originalName.setMiddle(name.getMiddle());
}
if (hasRoleB) { // (2)
originalName.setLast(name.getLast());
}
nameDao.save(originalName); // (3)
ModelAndView mav = new ModelAndView("pages/editName");
logger.debug(originalName.toString());
mav.addObject("name", originalName);
return mav;
}