title: spring data jpa composite key duplicate key record insertion resulting in update
body: <p>I have one entity having composite key and I am trying to persist it by using spring data jpa repository to mysql databse as given below:</p>
  
  <pre><code>@Embeddable
  public class MobileVerificationKey implements Serializable{
  private static final long serialVersionUID = 1L;
  
  @Column(name="CUSTOMERID")
  private Long customerId;
  
  @Column(name="CUSTOMERTYPE")
  private Integer customerType;
  
  @Column(name="MOBILE")
  private Long mobile;
  @Embeddable
  public class MobileVerificationKey implements Serializable{
  
      private static final long serialVersionUID = 1L;
  
      @Column(name="CUSTOMERID")
      private Long customerId;
  
      @Column(name="CUSTOMERTYPE")
      private Integer customerType;
  
      @Column(name="MOBILE")
      private Long mobile;
  //getter and setters
  }
  </code></pre>
  
  <p>And Entity as </p>
  
  <pre><code>@Entity
  @Table(name="mobileverificationdetails")
  public class MobileVerificationDetails {
  
      @EmbeddedId
      private MobileVerificationKey key;
  
      @Column(name="MOBILETYPE")
      private String mobileType;
  
      @Column(name="MOBILEPIN")
      private Integer mobilePin;
  //getters and setters
  
  }
  </code></pre>
  
  <p>My spring data jpa repository look like this:</p>
  
  <pre><code>public interface MobileVerificationDetailsRepository extends
          CrudRepository&lt;MobileVerificationDetails, MobileVerificationKey&gt; {
  
      @Override
      MobileVerificationDetails save(MobileVerificationDetails mobileVerificationDetails);
  
      @Override
      MobileVerificationDetails  findOne(MobileVerificationKey id);
  }
  </code></pre>
  
  <p>Now if I am trying to add duplicate record with same key for original record and different values for other fields .when i try to insert second record it results in update of existing record with new values instead of throwing exception for violating primary key constraint...can any one please explain me this behavior. </p>