删除父类同时删除其所在的子类
请教各位大神删除父类同时删除其所在的子类,父类和子类在同一张表里面。
这是拼的hql
for(String id : idArray){
params = new ArrayList<Integer>();
hql=new StringBuffer("delete from CustomerRating where crId in (");
hql.append("select a.crId from (");
hql.append("select crId from CustomerRating where pName in (");
hql.append("select cName from CustomerRating where crId = ? ");
hql.append(")) a ");
hql.append(") or crId = ?");
params.add(Integer.valueOf(id));
params.add(Integer.valueOf(id));
int result = ht.bulkUpdate(hql.toString(), params.toArray());
if(result <1){
return 0;
}
}
这是生成的sql,在数据库里能删除,但在后台就不能了
delete from CUSTOMERRATING where CRId in (
select a.CRId from (
select s.CRId from CUSTOMERRATING s where s.PName in (
select m.CName from CUSTOMERRATING m where m.CRId in (?)
)) a
) or CRId in (?)