thanks i have been able to do this by this code change -
1) I created a finder in entity - Mst_job_role.findMst_job_rolesByJob_roleEquals
2) Override create method in entity's controller and changed it as below -
Code:
@RequestMapping(method = RequestMethod.POST)
public String create(@Valid Mst_job_role mst_job_role,
BindingResult bindingResult, Model uiModel,
HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
uiModel.addAttribute("mst_job_role", mst_job_role);
return "mst_job_roles/create";
}
//uiModel.asMap().clear();
if (Mst_job_role.findMst_job_rolesByJob_roleEquals(mst_job_role.getJob_role()).getResultList().size() == 0) {
mst_job_role.persist();
return "redirect:/mst_job_roles/"+ encodeUrlPathSegment(mst_job_role.getId().toString(),httpServletRequest);
} else
return "mst_job_roles/create";
}
I had to comment clearing of uiModel
Code:
//uiModel.asMap().clear();
as I am sending back to create page if job role already exists.