Removing from ManyToMany using IndexColumn

Report.entity {
  @ManyToMany
  @JoinTable (name = "reports_contents_relations",
             joinColumns = @JoinColumn (name = "report_id"),
             inverseJoinColumns = @JoinColumn (name = "content_id"))
  @IndexColumn (name = "content_order")
private List contents = new ArrayList ();
}

Someclass {
  public void remoteContentFromReport (Content content) {
    List contents = report.getContents ();
    contents.remove (content);
    save (report);
  }
}

When I call the remoteContentFromReport method, I get the following error.

java.sql.BatchUpdateException: Duplicate record with collection

I do not want to delete Content.entity, just an entry in the connection table linking it to the report.

What am I missing?

+3
1

report.saveOrUpdate(), , report.contents ( ).

, .

+1

Source: https://habr.com/ru/post/1747382/


All Articles