//实体类关联--agent表的user_id关联着user 表的id主键
@OneToOne(cascade = { CascadeType.ALL }) @JoinColumn(name = "user_id") private User user ; //
删除操作
//删除商家 @RequestMapping("/delete_agent.do") @ResponseBody public Map<String,Object> delete_business(int id){ Map<String,Object> map=new HashMap<String,Object>(); Agent agent; try { agent=agentService.getbyId(id);//查询获取agent表对应id的数据--在这就查出了对应user表id关联的user_id agentService.delete(agent.getUser().getId());//调用删除方法,将user_id传到实现层 map.put("flag","1"); } catch (Exception e) { // TODO Auto-generated catch block logger.error("删除商家失败", e); map.put("flag","0"); } return map; }
实现层impl
@Override public int delete(int id) throws Exception { String hql="update User set status=0 where id=?";//在这里,虽然是agentimpl,但是能将hibernate语句更新user表 List<Object> param=new ArrayList<Object>(); param.add(id); return dao.exculeByParams(hql, param); }