title: DDD - Repository and many-to-many relationship
body: <p>I am new to DDD and I am stuck here:
  I have a many-to-many relationship between two entities: User and Group. The relationship is not an Aggregate because a User can exist without a Group and a Group can exist without a User.</p>
  <p>This is my code for the User class:</p>
  <pre><code>public class User {
  
      private List&lt;Group&gt; groups = new ArrayList&lt;Group&gt;();
      
      private UserRepository userRepository;
  
      public void create() throws Exception{
          userRepository.create(this);        
          
          // I have to update the groups with the user.
          for (Group group : groups) {
              group.update();
          }
      }
      
       public void addGroup(Group group){
          if (!groups.contains(group)) {
              groups.add(group);
              group.addUser(this);
           }
      }
  }
  </code></pre>
  <p>The problem is that I don't know where to associate those classes when I create a User who has groups in (I cannot use ORM). I made it in the create method of User, and I also manage transactions there through Spring. Is this correct? Or should I put that code in the userRepository or in a Service?</p>
  <p>Thanks!</p>