Hi,
We are using Spring for our development. In the project I have two entities - Iteration and Task which have ManyToMany relationship. Here is a definition:
Code:
@ManyToMany(
targetEntity=Task.class,
fetch = FetchType.LAZY,
cascade = CascadeType.REMOVE
)
@JoinTable(
name="Po_IterationTask",
joinColumns=@JoinColumn(name="iterationUuid"),
inverseJoinColumns=@JoinColumn(name="taskUuid")
)
private List<Task> tasks;
public Iteration() {
super();
}
now when I add Tasks to an Iteration and save it, it works ok. The tasks are added to the Iteration. But then I'd like to save the Iteration. My controller method looks like this:
Code:
@RequestMapping(method={ RequestMethod.POST, RequestMethod.PUT })
public @ResponseBody Map<String,? extends Object> save(@RequestBody Iteration iteration) {
try{
new ClassValidator<Iteration>(validator).validateRecord(iteration);
crudService.save(iteration);
return MessageProcessor.createRecordMessage(iteration);
} catch (Exception e) {
logger.error(e);
return MessageProcessor.createError(e.getLocalizedMessage());
}
}
Of course as Iteration is submitted from the Spring form, there is no tasks in the Iteration object. When I store the Iteration - action produces deletion of existing task links added to the iteration.
How to resolve this, without manually updating the collections on all ManyToMany entities?