hibernate中要删除数据时,如果数据被其他表数据关联的话会报错。怎么在删除前判断数据没有被关联。
举例:
user表 id,name
A表 id,userid
B表 id,userid现在要删除user表中数据user1时 如何判断A,B表中是否有数据和user1关联。
不能直接遍历A,B表 因为可能还会有C表,D表

解决方案 »

  1.   


    说了不能直接查询,如果有100个表和user关联 难道要查询100个表?
      

  2.   

    int k = 0; try {
    for (int i = 0; i < id.length; i++) {
    ids = id[i];
    if (ids.equalsIgnoreCase(businessReportingService.select(ids)
    .getId())) {
    k++;
    }
    }
    if (k > 0) {
    success = false;
    msg = "失败";
    } else {
    businessPlanService.delete(id); success = true;
    msg = "Successfully";
    } } catch (AppException e) {
    success = false;
    msg = e.getMessage();
    } catch (Exception e) {
    success = false;
    msg = "Faild";
    } return JsonUtils.toResponseResultView(success, msg);
    }