Applying Many to Many

many-to-many-header-img1
This is based on this section:


In controller method, it creates a relation ship between RTRN_TP and RTRN_RSN
1. RTRN_RSN object set to HashSet that part of fileds of RTRN_TP
2. RTRN_TP object is saved
many-to-many1
RTRN_RSN of “006”, “010”, and “011” have been bound to RTRN_TP of “01”
many-to-many-data2

@RequestMapping(value = "/cUrlValAttrbSubTpRsn01Jsp", params = "toUnBoundRsnList", method = RequestMethod.POST)
public ModelAndView toUnBoundRsnList(@ModelAttribute("RtrnTpModel") RtrnTpModel tp, ModelMap model, HttpServletRequest req) {

	String tpSelected = (String) req.getSession().getAttribute(CONST.TP_SELECTED.getVal());
	if (CommonBL.hasValue(tpSelected)) {
		List<String> selectedCheckBox = tp.getSelectedCheckBox();
		if (!CommonBL.isEmpty(selectedCheckBox)) {
			for (String code : selectedCheckBox) {
				RTRN_TP_RSN_CMBN tpRsnObj = this.tpRsnSvc.getTpRsnCmbnByHql(tpSelected, code);
				if (tpRsnObj != null) {
					this.tpRsnSvc.delete(tpRsnObj);
				}
			}
		}
	}
	return getMVSubTpRsn01(model, req);
}

Unlike adding the relationship, to delete (un-bound) the relationship, it’s directly deleting the Join Table (RTRN_TP_RSN_CMBN)