title: org.hibernate.exception.ConstraintViolationException: could not insert
body: <p>When I try to add into <code>TDEPOFAZLA</code> table, I get the following error: </p>
  
  <blockquote>
    <p>org.springframework.dao.DataIntegrityViolationException: could not insert: [tr.gov.tcmb.pgmtems.model.DepoFazla]; SQL [insert into PGMTEMS.TDEPOFAZLA (ID, FAZLABULUNDURMAORANI, GRUP) values (default, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [tr.gov.tcmb.pgmtems.model.DepoFazla]</p>
  </blockquote>
  
  <p>Here is my <strong>JUnit</strong> test function:</p>
  
  <pre><code>    @Test
  public void testSaveDepoFazla() {
      DepoTur depoTur = new DepoTur("my tür", 5);
      depoTurService.saveDepoTur(depoTur);
  
      List&lt;DepoTur&gt; list = depoTurService.getDepoTurList();
      assertNotNull(list.get(0));
  
      BigDecimal fazlaBulundurmaOrani = new BigDecimal(6000);
      DepoFazla depoFazla = new DepoFazla(1, list.get(0), fazlaBulundurmaOrani);
  
      depoFazlaService.saveDepoFazla(depoFazla);
  }
  </code></pre>
  
  <p>Here is my <strong>DepoFazla.java</strong>:</p>
  
  <pre><code>@Entity
  @Table(schema = "PGMTEMS", name = "TDEPOFAZLA")
  public class DepoFazla implements Serializable {
      private static final long serialVersionUID = -2800365387332643658L;
  
      @Id
      @GeneratedValue
      @Column(name = "ID", nullable = false, updatable = false)
      private Long id;
  
      @Column(name = "GRUP", nullable = false, columnDefinition = "INTEGER")
      private Integer grup;
  
      @ManyToOne(fetch = FetchType.LAZY, targetEntity = DepoTur.class)
      @JoinColumn(name = "ID", insertable = false, updatable = false)
      @NotNull
      private DepoTur depoTur;
  
      @Column(name = "FAZLABULUNDURMAORANI", nullable = false, columnDefinition = "DECIMAL(6, 2)")
      private BigDecimal fazlaBulundurmaOrani;
  
      public DepoFazla() {
          super();
      }
  
      public DepoFazla(Integer grup, DepoTur depoTur, BigDecimal fazlaBulundurmaOrani) {
          super();
          this.grup = grup;
          this.depoTur = depoTur;
          this.fazlaBulundurmaOrani = fazlaBulundurmaOrani;
      }
  //GETTER AND SETTER METHODS
  }
  </code></pre>
  
  <p>Here is <strong>DepoTur.java</strong>:</p>
  
  <pre><code>@Entity
  @Table(schema = "PGMTEMS", name = "TDEPOTUR")
  public class DepoTur implements Serializable {
      private static final long serialVersionUID = 6203672609079710060L;
  
      @Id
      @GeneratedValue
      @Column(name = "ID", nullable = false, updatable = false)
      @Index(name = "XUTDEPOTURP", columnNames = { "id" })
      private Long id;
  
      @Column(name = "ACIKLAMA", nullable = false)
      private String aciklama;
  
      @Column(name = "BLOKESIRASI", nullable = false)
      private Integer blokeSirasi; //
  
      @Column(name = "DEPOCINSI")
      private String depoCinsi;
  
      public DepoTur() {
          super();
      }
  
      public DepoTur(String aciklama, Integer blokeSirasi, String depoCinsi) {
          super();
          this.aciklama = aciklama;
          this.depoCinsi = depoCinsi;
          this.blokeSirasi = blokeSirasi;
      }
  
  public DepoTur(String aciklama, Integer blokeSirasi) {
      super();
      this.aciklama = aciklama;
      this.blokeSirasi = blokeSirasi;
  }
  //GETTER AND SETTER METHODS
  </code></pre>
  
  <p>When I debug the JUnit test, I get this error:</p>
  
  <blockquote>
    <p>Error: DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC=TBSPACEID=2, TABLEID=75, COLNO=2, DRIVER=3.50.152 SQLState: 23502 ErrorCode: -407</p>
  </blockquote>
  
  <p>When I search the error, I find that I try to insert NULL but I can't figure out where I add null value. </p>
  
  <p>This is how I create <strong>TDEPOFAZLA</strong> table:</p>
  
  <pre><code>    CREATE TABLE TDEPOFAZLA
  (
     ID decimal(20,0) PRIMARY KEY NOT NULL,
     GRUP int NOT NULL,
     DEPOTUR decimal(20,0) NOT NULL,
     FAZLABULUNDURMAORANI decimal(6,2) NOT NULL
  );
  CREATE UNIQUE INDEX XUTDEPOFAZLAP ON TDEPOFAZLA(ID);
  </code></pre>
  
  <p>This is how I create <strong>TDEPOTUR</strong> table:</p>
  
  <pre><code>CREATE TABLE TDEPOTUR
  (
     ID decimal(20,0) PRIMARY KEY NOT NULL,
     ACIKLAMA varchar(100) NOT NULL,
     DEPOCINSI char(1),
     BLOKESIRASI int NOT NULL
  );
  CREATE UNIQUE INDEX XUTDEPOTURP ON TDEPOTUR(ID);
  </code></pre>
  
  <p>Any ideas on what I should do?</p>