Hibernate: Refrain update on Many-to-Many insert <h2>Problem</h2> <p>I use hibernate to store data in an MySQL database. I now want to store a Company and one of its Branches.</p> <p>The company:</p> <pre><code>@Entity @Table(name="company") public class Company { @Id @GeneratedValue @Column(name="id") private int id; @Column(name="name") private String name; @ManyToMany(cascade = CascadeType.ALL) @JoinTable(name="company_branch_join", joinColumns={@JoinColumn(name="company_id")}, inverseJoinColumns={@JoinColumn(name="branch_id")}) private Set&lt;CompanyBranch&gt; branches; // Getters and setters... } </code></pre> <p>And the branch:</p> <pre><code>@Entity @Table(name="company_branch") public class CompanyBranch { @Id @GeneratedValue @Column(name="id") private int id; @Column(name="branch") private String branch; @ManyToMany(mappedBy="branches", cascade = CascadeType.ALL) private Set&lt;Company&gt; companies; // Getters and setters... } </code></pre> <h2>Question</h2> <p>The code works and i can insert the data in the join table. The problem is the override policy regarding the branches. My branch table in the database is already filled with branches and its IDs so i don't want to modify the data. However on an company-insert the branches associated with the company get stored again and override the data with the same ID in the database. How can I prevent this behavior?</p> <pre><code>CompanyBranch cb1 = new CompanyBranch(); cb1.setId(1); cb1.setBranch("Manufacturing"); CompanyBranch cb2 = new CompanyBranch(); cb2.setId(2); cb2.setBranch("DONT-INSERT"); Company c = new Company(); c.setName("[Random-Company-Name]"); c.addBranch(cb1); c.addBranch(cb2); CompanyManager cm = new CompanyManagerImpl(); cm.saveCompany(c); </code></pre> <p>The branch table before execution looks like this:</p> <pre><code>| id | branch | +----+----------------+ | 1 | Manufacturing | | 2 | IT | |... | ... | </code></pre> <p>The table should not change. But after execution it looks like this:</p> <pre><code>| id | branch | +----+----------------+ | 1 | Manufacturing | | 2 | DONT-INSERT | |... | ... | </code></pre>