Consider a class (an ORM entity):
public class MyEntity {
Long id;
MyOtherEntity assoc;
// ... getters and setters
}
I want for it to be bound automatically in a Spring MVC controller, something like that:
public ModelAndView method(HttpServletRequest request,
HttpServletResponse response, MyEntity command) {
}
It works well for simple properties like id, but for assoc it throws an exception NullValueInNestedPathException, since assoc wasn’t instantiated by constructor. The question is, how can I tell ServletRequestDataBinder (or BeanWrapper or anything) to instantiate properties automatically as it makes its way through the nested property path?
I could of course make another class derived from MyEntity and put an instantiation in it, but then I won’t be able to save it using simple Hibernate call, since derived class won’t be mapped.
Ok, one way to do that in case of
MultiActionControlleris to overridenewCommandObject; but I would like a more generic solution.