title: Constraint Violation While Inserting Entity
body: <p>I am getting a constraint violation, as follows:</p>
  
  <pre><code>MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'
  </code></pre>
  
  <p>My java classes are:</p>
  
  <pre><code>import com.fasterxml.jackson.annotation.JsonIgnore;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.ManyToOne;
  import javax.persistence.Table;
  import org.hibernate.annotations.GenericGenerator;
  
  
  @Entity    
  @Table(name = "channel")
  public class Channel
  {
      //@GeneratedValue(generator="gen")
      //@GenericGenerator(name="gen", strategy="foreign", parameters=@Parameter(name="property", value="employee"))
      @Id
      @GeneratedValue(generator="channel_gen")
      @GenericGenerator(name="channel_gen", strategy="increment")
      @Column(name = "channel_id", unique=true, nullable=false)
      @JsonIgnore
      private Long id;
  
      @JsonProperty(value = "name")
      @Column(name = "name")
      private String name;
  
      @JsonProperty(value = "start_freq")
      @Column(name = "start_freq")
      private int startFreq;
  
      @JsonProperty(value = "end_freq")
      @Column(name = "end_freq")
      private int endFreq;
  
      @JsonProperty(value = "center")
      @Column(name = "center")
      private int center;
  
      @JsonProperty(value = "bandwidth")
      @Column(name = "bandwidth")
      private int bandwidth;
  
      @ManyToOne
      @JoinColumn(name = "ID", nullable = false)
      private Report report;
  
      public Channel() {
  
      }
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public Report getReport() {
          return report;
      }
  
      public void setReport(Report report) {
          this.report = report;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public int getStartFreq() {
          return startFreq;
      }
  
      public void setStartFreq(int startFreq) {
          this.startFreq = startFreq;
      }
  
      public int getEndFreq() {
          return endFreq;
      }
  
      public void setEndFreq(int endFreq) {
          this.endFreq = endFreq;
      }
  
      public int getCenter() {
          return center;
      }
  
      public void setCenter(int center) {
          this.center = center;
      }
  
      public int getBandwidth() {
          return bandwidth;
      }
  
      public void setBandwidth(int bandwidth) {
          this.bandwidth = bandwidth;
      }   
  }
  </code></pre>
  
  <p>Another java class</p>
  
  <pre><code>import com.dgs.reports.utils.States;
  import com.fasterxml.jackson.annotation.JsonIgnore;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import java.util.List;
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.EnumType;
  import javax.persistence.Enumerated;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  import org.hibernate.annotations.GenericGenerator;
  
  @Entity    
  @Table(name = "report") 
  public class Report
  {
      @Id
      @GenericGenerator(name="report_gen" , strategy="increment")
      @GeneratedValue(generator="report_gen")
      @Column(name = "ID")
      @JsonIgnore
      private Long id;
  
  @JsonIgnore
  @Column(name = "state")
  @Enumerated(EnumType.STRING)
  private States state;
  
  @JsonProperty(value = "keyspace")
  @Column(name = "keyspace")
  private String keyspace;
  
  @JsonProperty(value = "quantum")
  @Column(name = "quantum")
  private int quantum;
  
  @JsonProperty(value = "quantum_string")
  @Column(name = "quantum_string")
  private String quantumString;
  
  @JsonProperty("report_type")
  @Column(name = "report_type")
  private String reportType;
  
  @JsonProperty("start_date")
  @Column(name = "start_date")
  private long startDate;
  
  @JsonProperty("end_date")
  @Column(name = "end_date")
  private long endDate;
  
  @JsonProperty("channels")
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "report")
  private List&lt;Channel&gt; channels;
  
  @JsonProperty("start_freq")
  @Column(name = "start_freq")
  private int startFreq;
  
  @JsonProperty("start_freq_unit")
  @Column(name = "start_freq_unit")
  private String startFreqUnit;
  
  @JsonProperty("end_freq")
  @Column(name = "end_freq")
  private int endFreq;
  
  @JsonProperty("end_freq_unit")
  @Column(name = "end_freq_unit")
  private String endFreqUnit;
  
  @JsonProperty("power")
  @Column(name = "power")
  private int power;
  
  
  
  public Long getId() {
      return id;
  }
  
  public void setId(Long id) {
      this.id = id;
  }
  
  public String getKeyspace() {
      return keyspace;
  }
  
  public void setKeyspace(String keyspace) {
      this.keyspace = keyspace;
  }
  
  public int getQuantum() {
      return quantum;
  }
  
  public void setQuantum(int quantum) {
      this.quantum = quantum;
  }
  
  public String getQuantumString() {
      return quantumString;
  }
  
  public void setQuantumString(String quantumString) {
      this.quantumString = quantumString;
  }
  
  public String getReportType() {
      return reportType;
  }
  
  public void setReportType(String reportType) {
      this.reportType = reportType;
  }
  
  public long getStartDate() {
      return startDate;
  }
  
  public void setStartDate(long startDate) {
      this.startDate = startDate;
  }
  
  public long getEndDate() {
      return endDate;
  }
  
  public void setEndDate(long endDate) {
      this.endDate = endDate;
  }
  
  public List&lt;Channel&gt; getChannels() {
      return channels;
  }
  
  public void setChannels(List&lt;Channel&gt; channels) {
      this.channels = channels;
  }
  
  public int getStartFreq() {
      return startFreq;
  }
  
  public void setStartFreq(int startFreq) {
      this.startFreq = startFreq;
  }
  
  public String getStartFreqUnit() {
      return startFreqUnit;
  }
  
  public void setStartFreqUnit(String startFreqUnit) {
      this.startFreqUnit = startFreqUnit;
  }
  
  public int getEndFreq() {
      return endFreq;
  }
  
  public void setEndFreq(int endFreq) {
      this.endFreq = endFreq;
  }
  
  public String getEndFreqUnit() {
      return endFreqUnit;
  }
  
  public void setEndFreqUnit(String endFreqUnit) {
      this.endFreqUnit = endFreqUnit;
  }
  
  public int getPower() {
      return power;
  }
  
  public void setPower(int power) {
      this.power = power;
  }
  
  public States getState() {
      return state;
  }
  
  public void setState(States state) {
      this.state = state;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>While inserting on the DB, I get this in the Catalina log file:
  <a href="https://i.stack.imgur.com/8VoAb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8VoAb.png" alt="enter image description here"></a></p>
  
  <p>My table's structures are:
  <a href="https://i.stack.imgur.com/9pzmt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9pzmt.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/qnWCM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qnWCM.png" alt="enter image description here"></a></p>
  
  <p>So the issue would be that, it seems that the auto increment feature doesnt seem to work as it's assigning always the same value to the channel entities... What I am missing ?.</p>