title: Java Entity java.sql.SQLException: Field 'id' doesn't have a default value
body: <p>I work with an API where I would like to have the Product ID as the String and supply myself. The model classes are provided, </p>
  
  <pre><code>@Entity
  public class Product{
  
  
      @Id
      @Column(name = "p_id")
      private String p_id;
  
      @Column(insertable = false, updatable = false, name = "p_timestamp")
      @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
      private Timestamp p_timestamp;
  
      @Embedded
      private Stock stock;
  
      public Product() {
  
      }
  
      public Product(String p_id, Timestamp p_timestamp, Stock stock) {
          this.p_id = p_id;
          this.p_timestamp = p_timestamp;
          this.stock = stock;
      }
  
      public String getP_id() {
          return p_id;
      }
  
      public void setP_id(String p_id) {
          this.p_id = p_id;
      }
  
      public Timestamp getP_timestamp() {
          return p_timestamp;
      }
  
      public void setP_timestamp(Timestamp p_timestamp) {
          this.p_timestamp = p_timestamp;
      }
  
      public Stock getStock() {
          return stock;
      }
  
      public void setStock(Stock stock) {
          this.stock = stock;
      }
  }
  
  
  
  
  import javax.persistence.Column;
  import javax.persistence.Embeddable;
  import java.sql.Timestamp;
  
  
  @Embeddable
  public class Stock {
  
      @Column(name = "s_id")
      private String s_id;
  
      @Column(name = "s_timestamp")
      @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
      private Timestamp s_timestamp;
  
      @Column(name = "s_s_quantity")
      private int s_quantity;
  
      public Stock() {
  
      }
  
      public Stock(String s_id, Timestamp s_timestamp, int s_quantity) {
  
          this.s_id = s_id;
          this.s_timestamp = s_timestamp;
          this.s_quantity = s_quantity;
      }
  
      public String getS_id() {
          return s_id;
      }
  
      public void setS_id(String s_id) {
          this.s_id = s_id;
      }
  
      public Timestamp getS_timestamp() {
          return s_timestamp;
      }
  
      public void setS_timestamp(Timestamp s_timestamp) {
          this.s_timestamp = s_timestamp;
      }
  
      public int getS_quantity() {
          return s_quantity;
      }
  
      public void setS_quantity(int s_quantity) {
          this.s_quantity = s_quantity;
      }
  }
  </code></pre>
  
  <p>The MySQL database is here, </p>
  
  <p><a href="https://i.stack.imgur.com/Wo0WD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wo0WD.png" alt="enter image description here"></a></p>
  
  <p>I pass the cURL command via the terminal,</p>
  
  <pre><code>$ curl -i -X POST -H "Content-Type:application/json" -d "{  \"p_id\": \"Product ID\", \"p_timestamp\": \"2017-07-16 22:54:01.754\",  \"stock\" : {  \"s_id\": \"Stock ID\", \"s_timestamp\": \"2000-07-16 22:54:01.754\",  \"s_quantity\": \"250\"  }}" http://localhost:8080/api/v1/products/createProduct
  </code></pre>
  
  <p>I get the error message, </p>
  
  <pre><code>java.sql.SQLException: Field 'id' doesn't have a default value
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.15.jar:8.0.15]
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.15.jar:8.0.15]
      at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.15.jar:8.0.15]
      at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:970) ~[mysql-connector-java-8.0.15.jar:8.0.15]
      at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1109) ~[mysql-connector-java-8.0.15.jar:8.0.15]
      at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1057) ~[mysql-connector-java-8.0.15.jar:8.0.15]
      at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1377) ~[mysql-connector-java-8.0.15.jar:8.0.15]
      at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1042) ~[mysql-connector-java-8.0.15.jar:8.0.15]
      at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) ~[HikariCP-3.2.0.jar:na]
      at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java) ~[HikariCP-3.2.0.jar:na]
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:175) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3171) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3686) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:90) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:478) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:356) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1454) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:511) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3283) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2479) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:473) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:178) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$300(JdbcResourceLocalTransactionCoordinatorImpl.java:39) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:271) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
      at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:98) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
  </code></pre>
  
  <p>How do I set the default value for the id? Thank you.  </p>