title: Duplicate entry for key 'PRIMARY' using JPA to persist into database
body: <p>I have an error with JPA persisting into my database, the error occurs when i persist a second file into the DB. I have a requirement to import numerous datasets, with 5 sheets each. There is a requirement to update each table even if some of the same data is already in there. At the moment i get the following error</p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>17:26:35,315 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-1) SQL Error: 1062, SQLState: 23000
  17:26:35,316 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-1) Duplicate entry '0' for key 'PRIMARY'
  </code></pre>
  
  <p><strong>Database Script</strong></p>
  
  <p>My script to create the DB is as follows:</p>
  
  <pre><code>CREATE DATABASE IF NOT EXISTS sampleDB;
  
  
  
  use sampleDB;
  
  
  
  CREATE TABLE IF NOT EXISTS `Table1`(`mcc` int(10) NOT NULL,`mnc` int(10) NOT NULL,`operator` varchar(50) DEFAULT NULL,`country` varchar(50) DEFAULT NULL,
  
      PRIMARY KEY (`mcc`,`mnc`))ENGINE=InnoDB;
  
  
  
  CREATE TABLE IF NOT EXISTS `Table2`(`tac` int(10) NOT NULL,`marketingName` varchar(50) DEFAULT NULL,`manufacturer` varchar(50) DEFAULT NULL,
  
      `accessCapability` varchar(200) DEFAULT NULL,`model` varchar(50) DEFAULT NULL,`vendorName` varchar(50) DEFAULT NULL,
  
      `ueType` varchar(20) DEFAULT NULL,`os` varchar(20) DEFAULT NULL,`inputMode` varchar(20) DEFAULT NULL,PRIMARY KEY (`tac`))ENGINE=InnoDB;
  
  
  
  CREATE TABLE IF NOT EXISTS `Table3`(`causeClass` varchar(10) NOT NULL,`description` varchar(255) NOT NULL,PRIMARY KEY (`causeClass`))ENGINE=InnoDB;
  
  
  
  CREATE TABLE IF NOT EXISTS `Table4`(`causeCode` int(5) NOT NULL,`eventId` int(5) NOT NULL,`description` varchar(255) DEFAULT NULL,
  
      PRIMARY KEY (`causeCode`,`eventId`) ON UPDATE NO ACTION))ENGINE=InnoDB;
  
  
  
  CREATE TABLE IF NOT EXISTS `Table5`(`baseDataTableId` int(11) NOT NULL AUTO_INCREMENT,`dateTime` DATETIME NOT NULL,`eventId` int(5) NOT NULL,`causeClass` varchar(10) NOT NULL,
  
    `ueType` int(15) NOT NULL,`market` int(10) NOT NULL,`operator` int(10) NOT NULL,`cellId` tinyint(2) DEFAULT NULL,`duration` smallint(7) DEFAULT NULL,
  
    `causeCode` int(5) NOT NULL,`neVersion` varchar(7) DEFAULT NULL,`imsi` varchar(255) DEFAULT NULL,`hier3Id` varchar(255) DEFAULT NULL,`hier32Id` varchar(255) DEFAULT NULL,
  
    `hier321Id` varchar(255) DEFAULT NULL,PRIMARY KEY (`baseDataTableId`))ENGINE=InnoDB;
  </code></pre>
  
  <p><strong>Java Hibernate properties</strong></p>
  
  <p>My Hibernate properties are as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0"
     xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="
          http://java.sun.com/xml/ns/persistence
          http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
     &lt;persistence-unit name="primary"&gt;
        &lt;jta-data-source&gt;java:jboss/datasources/MySqlDS&lt;/jta-data-source&gt;
        &lt;properties&gt;
           &lt;!-- Properties for Hibernate --&gt;
           &lt;property name="hibernate.hbm2ddl.auto" value="update" /&gt;
           &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /&gt;
           &lt;property name="hibernate.show_sql" value="false" /&gt;
           &lt;property name="hibernate.format_sql" value="false" /&gt;
        &lt;/properties&gt;
     &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p><strong>Java</strong></p>
  
  <p>Entity Class example:</p>
  
  <pre><code>@Entity
  @Table(name = "Table3")
  public class Table3 {
  
          @Id
          private int causeClass;
          private String description;
  
          public Table3(){}
  
          public Table3(int causeClass, String description) {
              super();
              this.causeClass = causeClass;
              this.description = description;
          }
  
          // getters &amp; setters
  
  }
  </code></pre>
  
  <p>Any ideas how to solve this problem?</p>