开发者

can not delete the entity using session.delete()

I have some entity in my application,and some of them are many-to-many association,when I try to delete them I get the error:"Cannot delete or update a parent row: a foreign key constraint....".

This is the example:

class Task{
  @OneToMany(mappedBy="task")
  List<TaskStep> steps;
}
class TaskStep{
  @ManyToOne(cascade=CascadeType.ALL)
  Task task;
  @ManyToM开发者_StackOverflow中文版any(cascade=CascadeType.ALl)
  List<Operator> operators
}
class Operator{
  @ManyToMany(mappedBy=opertors)
  List<TaskStep> steps;
}

When I want to delete a task object,I will get the exception.

Why? I just want to delete the task object itself, and the related rows in the t_taskstep_t_operator.

How to make this?


try this,

class Task{
  @OneToMany(cascade = CascadeType.ALL)
  List<TaskStep> steps;
}

It will delete the corresponding entry from TaskStep as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜