title: Check if User object exists in @DBRef List<User>
body: <p>I'm making use of MongoDB, Spring Data and Spring MVC.
  I have a user model which has a list of contacts:</p>
  
  <pre><code>class User {
  @DBRef
  private List&lt;User&gt; contacts = new ArrayList&lt;User&gt;(); 
  
  public List&lt;User&gt; getContacts() {
      return contacts;
  }
  }
  </code></pre>
  
  <p>I currently have 4 users inside my database. 1 user has a particular contact (who is referred to the same collection by id).</p>
  
  <p>Now, I want to check whether a user has a particular contact. I use the following code:</p>
  
  <pre><code>User userLoggedIn = userService.getLoggedInUser(); //user object
  User contact = userService.findById(contactId); //contact
  if(userLoggedIn.getContacts().contains(contact)) {
      System.out.println("Has this contact.");
  }
  </code></pre>
  
  <p>This output message is not shown. However, if I print the list of contacts of the user and their id's, I clearly see that the contact is inserted inside the list of the user.</p>
  
  <p>I noticed that if I print the hashCode of the contact object and the one that is inside the list, I get a different value, so  I assume that even though the details are the same, the object itself isn't.</p>
  
  <p>How can I approach this problem by simply checking whether he is inside the list. Or should I just compare by id?</p>
  
  <p><strong>Otherwise stated: how can I check whether an object exists in the contacts list?</strong></p>