Finally, I got a nice working solution after having a more detailed look on the stack trace. Saves everything in a transaction:
Code:@Autowired private ConversionService conversionService; @Autowired private Validator validator; ... @RequestMapping(method = RequestMethod.POST) @Transactional public String edit(@PathVariable("type") final String type, Model model, HttpServletRequest req) throws Exception { // retrieve command object Object entity = getCommand(type, req); // validate and bind request data, manually ServletRequestDataBinder binder = new ServletRequestDataBinder(entity); binder.setConversionService(conversionService); binder.setValidator(validator); binder.bind(req); binder.validate(); BindingResult result = binder.getBindingResult(); if (model!=null) // publish BindingResult in model model.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, result); // do save entity or display error Long id = getId(entity); if (result.hasErrors()) { // validation failed prepareModel(model, type, type + (id==null ? ".create" : ".update"), entity); return getViewName(type, "edit"); } // save entity if (id==null) facade.create(entity); else facade.edit(entity); return "redirect:/system/" + type + "/" + encodeUrlPathSegment(getId(entity).toString(), req) + "/edit"; } ...


Reply With Quote