title: How can you make a created_at column generate the creation date-time automatically like an ID automatically gets created?
body: <p>I currently have an Entity as below:</p>
  
  <pre><code>@Entity
  public class Product {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long productId;
      private String productImage;
      private String productTitle;
      private String productDescription;
      private Integer productPrice;
      private Date createdAt;
      private Date updatedAt;
  </code></pre>
  
  <p>Upon creation of this object, the value of createdAt and updatedAt shows null in the database and was wondering how I can implement code so that createdAt and updateAt automatically gets inserted?</p>
  
  <p>My post method is as below:</p>
  
  <pre><code>@PostMapping("/products")
  public ProductResponse createProduct(@Validated @RequestBody ProductForm productForm) {
      Product product = productForm.asProduct();
      Product createdProduct = productRepository.save(product);
      return new ProductResponse(createdProduct, "Product created");
  }
  </code></pre>