title: Duplicate entry - MySQLIntegrityConstraintViolationException: Duplicate entry 'visin' for key 'UK_n4350d6kihgn8ls1p4508pwut'
body: <p>I'm using in my application spring-data-jpa 1.9.2, mysql-connector 5.1 and hibernate 4.3.11 Final.</p>
  
  <p>I'm having a ManyToOne association between Marketvalue and value : </p>
  
  <pre><code>@Entity
  @Table(name = "MarketValues")
  public class MarketValue implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
  @ManyToOne(targetEntity = Value.class)
  @JoinColumn(nullable = false, name = "value_isin", referencedColumnName = "isin")
  private Value value;
  private Date date;
  private double cours;
  public MarketValue() {
  }
  }
  
  @Entity
  public class Value implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
  private String name;
  private String isin;
  private String nature;
  @OneToMany(mappedBy = "value")
  private Collection&lt;MarketValue&gt; marketvalues;
  @ManyToOne(targetEntity = Entreprise.class, fetch = FetchType.EAGER)
  @JoinColumn(name = "entreprise_name", referencedColumnName = "name")
  private Entreprise entreprise;
  public Value() {
      super();
  }
  </code></pre>
  
  <p>when I try to save two marketvalues with the same value isin :</p>
  
  <pre><code>Entreprise e = new Entreprise("ename",3232123123.3,"edesc");
  Value v = new Value("vname","visin","vnature", e);
  MarketValue mv = new MarketValue(v,22.3,date);
  MarketValue mv2 = new MarketValue(v,20.0,date2);
  eRepository.save(e);
  vRepository.save(v);
  mvRepository.save(mv);
  mvRepository.save(mv2); //exception here
  </code></pre>
  
  <p>I get this when saving the 2nd marketvalue.</p>
  
  <p>[...]</p>
  
  <pre><code>caused by : com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'visin' for key 'UK_n4350d6kihgn8ls1p4508pwut'
  at sun.reflect.GeneratedConstructorAccessor85.newInstance(Unknown Source) ~[na:na]
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_91]
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_91]
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.Util.getInstance(Util.java:387) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:932) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5094) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  </code></pre>
  
  <p><strong>^SOLVED</strong></p>
  
  <p>I had another table which references the column "value_isin" of <code>MarketValue</code> that made the column "value_isin" UNIQUE and so the <code>ManyToOne</code> association is behaving like a <code>OneToOne</code> association.</p>