title: JPA: how to persist many to many relation
body: <p>I have these 2 entity with many to many relationship.</p>
  
  <pre><code>@Entity
  public class User {
  
      @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
      private List&lt;User&gt; users = new ArrayList&lt;User&gt;();
  }
  
  @Entity
  public class Language {
      @ManyToMany(mappedBy = "languages")
      private List&lt;User&gt; users = new ArrayList&lt;User&gt;();
  }
  </code></pre>
  
  <p>I already have 20 languages saved in my language table. Now, I want to create a user and give relate that user with first language in the language table. So I did something like this</p>
  
  <pre><code>    Language selectedLanguage = languageService.findById(1);
      stammdaten.getLanguages().add(selectedLanguage);
      stammdatenService.save(stammdaten);
  </code></pre>
  
  <p>But this gives me error <code>org.hibernate.PersistentObjectException: detached entity passed to persist: com.example.outgoing.Entity.Language</code>. So how can I save this many to many relation. One thing to note here: I don't want to add new language. I want to add new user with already created languages.</p>