title: Will JPA try to cascade persist and already persistent entity?
body: <p><strong>Will JPA try to cascade persist on an entity that is already persistent (and non-detached)?</strong></p>
  <p>To make things clear, here's my situation: I want to persist a new User:</p>
  <pre><code>public void addUser(){
      //User is an entity that is related to many Groups
      //The relationship on User side is marked with cascade persist
      User user = new User();
      user.setName(&quot;foo&quot;);
      user.setGroups(new ArrayList&lt;Groups&gt;());
  
      //selectedGroups is an List of Groups previously created with persistent Groups
      for(Group g : this.selectedGroups){
          user.getGroups().add(this.groupDao.find(g.getId()));
      }
      //At this point, User.getGroups() is a list of Managed Entities
  
      //What happens on the following line?
      userDao.persist(user);
  }
  </code></pre>
  <p>So, what happens? Will JPA try to persist (again) every single group in user.getGroups()? Or will it detect that those groups already exist and just update new relations?</p>
  <p>In case of 'Yes, it will persist again', how should I annotate this relation to make that code work properly?</p>