Reputation: 1596
I have two class one is task and other agent .Task has a list of agents as below
@ManyToMany(cascade=CascadeType.ALL)
@JoinTable(name = "TASK_AGENT", joinColumns = @JoinColumn(name = "TID"),
inverseJoinColumns = @JoinColumn(name = "AID"))
private List<Agent> agents=new ArrayList<Agent>();
I want to remove agent even if it referenced some task.Is there any way do this entitymanager.remove(agent) giving constraint violation exception.Where and how i must declare a cascade i cant declare it on agent because relation should be unidirection.
Upvotes: 0
Views: 2600
Reputation: 803
You can query all the tasks that containt the agent you want to remove and remove it from their collection. Then update the referenced tasks, update the task you are playing with and delete the agent.
Upvotes: 1