title: Why is it needed to override equals() and hashcode() using Set for many-value associations?
body: <p>In <a href="http://docs.jboss.org/hibernate/core/4.0/manual/en-US/html/persistent-classes.html#persistent-classes-equalshashcode" rel="nofollow noreferrer">hibernate manual</a> it is said that you have to override the equals() and hashCode() methods if you intend to put instances of persistent classes in a Set (the recommended way to represent many-valued associations).</p>
  
  <p>So the questions appeared:</p>
  
  <ul>
  <li><p>Why is it a recommended way to represent many-value associations in a set?(Why shouldn't I use, let's say, ArrayList or LinkedList).</p></li>
  <li><p>What happens behind the scene that I should override those methods only when I use Set?</p></li>
  </ul>