Hibernate级联删除

来源:互联网 发布:淘宝描述代码 编辑:程序博客网 时间:2024/06/10 23:47


  在使用Hibernate框架的时候,有时候会用到级联删除:在删除主表记录前,将记录所关联的表的信息一并删除,这里没有用到配置,而是逻辑来实现 。

/* 删除 */@Transactionalpublic boolean delOper(Long operId){boolean status = false;try{//删t_operator表记录之前先要删除t_sys_log表所关联的记录List<Object> params = new ArrayList<Object>(); StringBuffer hql = new StringBuffer();hql.append(" delete from t_sys_log l where l.created_by=?");params.add(operId);hibernateDao.updateBySql(hql.toString(), params.toArray());hibernateDao.delete(TOperator.class, operId);status = true;}catch(Exception ex){logger.error(ErrorCodeConstants.ERROR_1_DB, ErrorCodeConstants.ERROR_DB_2);ex.printStackTrace();}return status;}


0 0
原创粉丝点击