title: spring jpa - a different object with the same identifier value was already associated with the session
body: <p>Searched through SO but looks like there is no similar case to mine.</p>
  
  <p>There is an entity Country, with a single field:</p>
  
  <pre><code>public class Country {
  
      @Id
      @Column(name = "COUNTRY_CODE")
      private String countryCode;
  
      public boolean equals(Object o) {}
  
      public int hashCode() { }
  }
  </code></pre>
  
  <p>And another class which has a collection of these entries:</p>
  
  <pre><code>public class Product {
  
      @ManyToOne(fetch = EAGER, cascade = ALL)
      @JoinColumn(name = "COUNTRY_CODE")
      private Country country;
  }
  </code></pre>
  
  <p>When setting country through:</p>
  
  <pre><code>product.setCountry(new Country("lv"))
  </code></pre>
  
  <p>I assume that it will just be saved, if it is present.</p>
  
  <p>But instead I get an exception - a different object with the same identifier value was already associated with the session</p>