title: Persist all the fields properly in the MySQL
body: <p>I work with a small API where I have all the data before I persist in the database and I can print them accordingly. So, it seems the code works as intended, but, I wasn't able to persist them in the MySQL. The entity classes are provided, </p>
  
  <pre><code>@Entity
  public class Product {
  
      @Id
      @Column(name = "id")
      private String id;
  
  
      @Column(insertable = false, updatable = false, name = "timestamp")
      @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
      private java.sql.Timestamp timestamp;
  
      @Embedded
      private Stock stock;
  
      public Product() {
  
      }
  
      public Product(String id, Timestamp timestamp, Stock stock) {
          this.id = id;
          this.timestamp = timestamp;
          this.stock = stock;
      }
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public Timestamp getTimestamp() {
          return timestamp;
      }
  
      public void setTimestamp(Timestamp timestamp) {
          this.timestamp = timestamp;
      }
  
      public Stock getStock() {
          return stock;
      }
  
      public void setStock(Stock stock) {
          this.stock = stock;
      }
  }
  
  
  
  @Embeddable
  public class Stock {
  
      @Id
      @Column(name = "id")
      private String id;
  
      @Column(name = "timestamp")
      @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss.SSS")
      private java.sql.Timestamp timestamp;
  
      @Column(name = "quantity")
      private int quantity;
  
      public Stock() {
  
      }
  
      public Stock(String id, Timestamp timestamp, int quantity) {
  
          this.id = id;
          this.timestamp = timestamp;
          this.quantity = quantity;
      }
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public Timestamp getTimestamp() {
          return timestamp;
      }
  
      public void setTimestamp(Timestamp timestamp) {
          this.timestamp = timestamp;
      }
  
      public int getQuantity() {
          return quantity;
      }
  
      public void setQuantity(int quantity) {
          this.quantity = quantity;
      }
  }
  </code></pre>
  
  <p>The API is provided below, </p>
  
  <pre><code>@RestController
  @RequestMapping("/api/v1/products")
  public class ProductAPI {
  
  
      @Autowired
      private ProductService service;
  
  
      /*
       *
       * $ curl -i -X POST -H "Content-Type:application/json" -d "{ \"id\": \"Product1 ID\", \"timestamp\": \"2017-07-16 22:54:01.754\", \"stock\" : { \"id\": \"Stock ID\", \"timestamp\": \"3000-07-16 22:54:01.754\", \"quantity\": \"350\" }}" http://localhost:8080/api/v1/products/createProduct
       * */
      @PostMapping(value = "/createProduct", consumes = "application/json", produces = "application/json")
      public ResponseEntity&lt;Product&gt; createProduct(@RequestBody Product product) {
  
  
          System.out.println("\n");
          System.out.println("Product ID " + product.getId());
          System.out.println("Product timestamp " +product.getTimestamp());
  
          System.out.println("Stock ID " +product.getStock().getId());
          System.out.println("Stock timestamp " +product.getStock().getTimestamp());
          System.out.println("Stock quantity " +product.getStock().getQuantity());
          System.out.println("\n");
  
          service.save(product);
          return ResponseEntity.status(HttpStatus.CREATED).body(product);
      }
  }
  </code></pre>
  
  <p>I made this cURL call for the persisting operation in the database, </p>
  
  <pre><code>$ curl -i -X POST -H "Content-Type:application/json" -d "{ \"id\": \"Product1 ID\", \"timestamp\": \"2017-07-16 22:54:01.754\", \"stock\" : { \"id\": \"Stock ID\", \"timestamp\": \"3000-07-16 22:54:01.754\", \"quantity\": \"350\" }}" http://localhost:8080/api/v1/products/createProduct
  </code></pre>
  
  <p>My print says that all the data came as wished, </p>
  
  <pre><code>Product ID Product1 ID
  Product timestamp 2017-07-17 00:54:01.754
  Stock ID Stock ID
  Stock timestamp 3000-07-17 00:54:01.754
  Stock quantity 350
  </code></pre>
  
  <p>This is good, but, when I look into the MySQL database, I find that the product timestamp and stock ID are missing. </p>
  
  <p><a href="https://i.stack.imgur.com/WDCyD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WDCyD.png" alt="enter image description here"></a></p>
  
  <p>For the product timestamp, I need to use the <code>insertable = false, updatable = false</code>, otherwise, I get an error. Not sure why the Stock id is not persisting. I can provide the repo and the service code if requested. </p>
  
  <p>How do I persist the data properly in the MySQL?</p>
  
  <p><em>UPDATE</em></p>
  
  <p>When I removed the @Id annotation form the Stock and renamed it to id1, I am able to persist the value into the database. I am still not able to persist the timestamp for the product into the database. </p>
  
  <p><a href="https://i.stack.imgur.com/xnQFA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xnQFA.png" alt="enter image description here"></a></p>