title: Spring : java.sql.SQLException: Field '**' doesn't have a default value
body: <p>My Entity is a  data class has default values and the json is being received in the server in the post api call but one field, which is not present in the data class is always null for some reason.</p>
  <pre><code>@Entity
  @Table(name = &quot;checking_point&quot;)
  data class CheckingPointEntity(
  
      @Column(nullable = false, unique = false, length = 500)
      open var name: String = &quot;&quot;,
  
      @Column(nullable = false, unique = false, length = 500)
      open var description: String = &quot;&quot;,
  
      @Column(nullable = false)
      open var cpTypeId: Int = 0,
  
      @Column(nullable = false)
      open var isCumulative: Boolean = false,
  
      @Column(nullable = false)
      open var cpCategoryGroupId: Long = 0L,
  
      @Column(nullable = false)
      open var isTemplate: Boolean = false,
  
      @Column(nullable = false)
      open var isTopTemplate: Boolean = false
  
  ) : BkpBaseEntity1()
  </code></pre>
  <p>BastEntity1 :</p>
  <pre><code>@MappedSuperclass
  open class  BkpBaseEntity1 {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      open var id:Long = 0L
  
      // **************************************************************************
      // *****    Below 4 columns should be there in each and every table   *******
      // **************************************************************************
  
      @Column(nullable = false, updatable = false,  columnDefinition = &quot;varchar(100) default 'adhoc-sql'&quot;)
      open var dbCreateSource: String = BkpConstants.DB_CREATE_SOURCE_NAME;
  
  
      @JsonFormat(pattern = &quot;yyyy-MM-dd HH:mm:ss&quot; )
      @Temporal(TemporalType.DATE)
      @Column(nullable = false,insertable = false, updatable=false, columnDefinition = &quot;datetime DEFAULT now()&quot;)
      open var dbCreateDts: Date = Date() //Do not set this field. It will be populated by DB.
  
  
      @Column(nullable = false, columnDefinition = &quot;varchar(100) default 'adhoc-sql'&quot;)
      open var dbUpdateSource: String = BkpConstants.DB_CREATE_SOURCE_NAME;
  
      @Column(nullable = false, insertable = false, updatable=false, columnDefinition = &quot;datetime  NOT NULL DEFAULT now() on update now()&quot;)
      @Temporal(TemporalType.DATE)
      @JsonFormat(pattern = &quot;yyyy-MM-dd HH:mm:ss&quot;)
      open var dbUpdateDts: Date = Date() //Do not set this field. It will be populated by DB.
  
  }
  </code></pre>
  <p>Controller :</p>
  <pre><code>@RequestMapping(path = [ControllerEndPoints.AddCheckingPoint], method = [RequestMethod.POST])
      fun addCheckingPoint(@RequestBody(required = true) reqData: ChartServerVo): ResponseEntity&lt;ChartAck&gt; {
          mLog(&quot;in add cp &quot;)
          var cpId = 0L
          var pcId = 0L
           val cpDto : CheckingPointDto = reqData.checkingPointDto
          val gson = GsonBuilder().setDateFormat(&quot;yyyy-MM-dd HH:mm:ss&quot;).create()
          val payload = gson.toJson(reqData)
          mLog(&quot;json: \n json $payload &quot;)
              mLog(&quot;json: saved cpDto name ${cpDto.name}, description ${cpDto.description} cpTypeId ${cpDto.cpTypeId} isCumulative ${cpDto.isCumulative} categoryGroupId ${cpDto.cpCategoryGroupId} isTemplate&quot;)
              cpr.save(cpDto.toEntity())
  ...................
  }
  </code></pre>
  <p>Json received by the server has all the fields</p>
  <pre><code>    {&quot;checkingPointDto&quot;:{&quot;name&quot;:&quot;demo&quot;,&quot;description&quot;:&quot;&quot;,&quot;cpTypeId&quot;:1,&quot;isCumulative&quot;:false,&quot;cpCategoryGroupId&quot;:16,&quot;isTemplate&quot;:false,&quot;isTopTemplate&quot;:false,&quot;id&quot;:0,&quot;dbCreateSource&quot;:&quot;&quot;,&quot;dbCreateDts&quot;:&quot;2022-03-08 21:07:32&quot;,&quot;dbUpdateSource&quot;:&quot;&quot;,&quot;dbUpdateDts&quot;:&quot;2022-03-08 21:07:32&quot;},&quot;purusharthChartCpMappingDto&quot;:{&quot;id&quot;:0,&quot;purusharthChartId&quot;:16466443,&quot;cpId&quot;:0},&quot;purusharthChartDto&quot;:{&quot;id&quot;:16466443,&quot;adminID&quot;:8,&quot;name&quot;:&quot;demo&quot;,&quot;description&quot;:&quot;&quot;,&quot;userId&quot;:8,&quot;startDate&quot;:&quot;2022-03-08 21:07:32&quot;,&quot;endDate&quot;:&quot;2022-12-30 21:07:32&quot;,&quot;isSelfChart&quot;:false},&quot;isNewchart&quot;:false} 
  </code></pre>
  <p>The error says that a field <code>cp_type_id</code> that isn't anywhere in the entity is null.</p>
  <pre><code>java.sql.SQLException: Field 'cp_type_id' doesn't have a default value
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.25.jar:8.0.25]
  </code></pre>
  <p>The only other place that I can find this field is in a .sql file.
  I am new to spring I do not know what it is supposed to do. As far as my sql knowledge goes it looks ok to me</p>
  <pre><code>create table checking_point(
      id int primary key NOT NULL auto_increment,
      name_str_id int,
      foreign key(name_str_id) references localization(id),
      description_str_id varchar(500),
      cp_type_id int,
      foreign key(cp_type_id) references dim_cp_type(id),
      cp_category_group_id int,
      foreign key(cp_category_group_id) references cp_category_group(id),
      repeat_type_id int,
      foreign key(repeat_type_id) references dim_repeat_type(id),
      cp_repeat_reminder_id int,
      is_template boolean,
      is_top_template boolean,
      db_create_dts date,
      db_create_source nvarchar(320),
      db_updated_dts date,
      db_update_source nvarchar(320)
  );
  </code></pre>
  <p>What am I missing? why is that filed which isn't even present in the entity in question causing this issue ?</p>