title: Want to automatically insert current Date in the table When a post Request is made
body: <p>I have a User Entity and an Order Entity.
  One of the field in order entity is date.
  Till now i have the user enter the date.
  Now i want that at the time post request is made the date is automatically set to the current date and stored in the database.</p>
  
  <p>Tried using @Prepersist annotation But since this is my first API that i am developing using springBoot , I don't really know how to use it.</p>
  
  <p>User Entity</p>
  
  <pre><code>    @Entity
  public class User {
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private BigInteger id;
  
      @NotEmpty(message = "Name is compulsory")
      @Pattern(regexp="^[A-Za-z]*[A-Za-z-'. ]*[A-Za-z]*$",message = "Name has invalid characters")
      private String username;
  
      //@NotEmpty(message = "Phone Number is compulsary")
      @Range(min = 6400000000L ,max=9999999999L)
      private Long phoneNumber;
  
      @NotEmpty(message = "Address is compulsary")
      private String address;
  
      public User(){}
  
      public User(BigInteger id, String username, Long phoneNumber, String address) {
          super();
          this.id = id;
          this.username = username;
          this.phoneNumber = phoneNumber;
          this.address = address;
  
      }
  
      public BigInteger getId() {
          return id;
      }
  
      public void setId(BigInteger id) {
          this.id = id;
      }
  
      public String getUsername() {
          return username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public Long getPhoneNumber() {
          return phoneNumber;
      }
  
      public void setPhoneNumber(Long phoneNumber) {
          this.phoneNumber = phoneNumber;
      }
  
      public String getAddress() {
          return address;
      }
  
      public void setAddress(String address) {
          this.address = address;
      }
  }
  </code></pre>
  
  <p>Order Entity</p>
  
  <pre><code> @Entity
  public class Orders {
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private BigInteger id;
  
      @CreationTimestamp
      @Temporal(TemporalType.TIMESTAMP)
       private Date date;
  
      @ManyToOne
      private User user;
  
      public Orders(){}
      public Orders(BigInteger id, Date date,BigInteger userId) {
          super();
          this.id = id;
          this.date = date;
          this.user=new User(userId," ",0000000000L," ");
      }
  
      public BigInteger getId() {
          return id;
      }
  
      public void setId(BigInteger id) {
          this.id = id;
      }
  
      public Date getDate() {
          return date;
      }
  
      public void setDate(Date date) {
          this.date = date;
      }
  
      public User getUser() {
          return user;
      }
  
      public void setUser(User user) {
          this.user = user;
      }
  }
  </code></pre>
  
  <p>Order Controller</p>
  
  <pre><code>    @RestController
  public class OrdersController {
  
      @Autowired
      private OrdersService ordersService;
  
      @ApiOperation(value="Show all orders")
      @RequestMapping("/orders")
      public Iterable&lt;Orders&gt; getAllOrders()
      {
          return ordersService.getAllOrders();
      }
  
      @ApiOperation(value="Show a particular Order")
      @RequestMapping("/orders/{orderId}")
      public Orders getOrderById(@PathVariable BigInteger orderId)
      {
          return ordersService.getOrderById(orderId);
      }
  
      @ApiOperation(value="Show all orders of a particular User")
      @RequestMapping("/users/{id}/orders")
      public List&lt;Orders&gt; getOrders(@PathVariable BigInteger id) {
          return ordersService.getOrders(id);
      }
  
      @ApiOperation(value="Show an order for a User")
      @RequestMapping("/users/{userId}/orders/{id}")
      public Orders getOrder(@PathVariable BigInteger id){
          return ordersService.getOrder(id);
      }
  
      @ApiOperation(value="Adds a new Order")
      @RequestMapping(method = RequestMethod.POST,value = "/users/{userId}/orders")
      public Orders addOrder(@PathVariable BigInteger userId,@RequestBody Orders orders) {
          orders.setUser(new User(userId," ",0000000000L," "));
          return ordersService.addOrder(orders);
      }
  
      @ApiOperation(value="Alter an Order")
      @RequestMapping(method = RequestMethod.PUT, value="/users/{userId}/orders/{id}")
      public Orders updateOrder(@RequestBody Orders order,@PathVariable BigInteger id,@PathVariable BigInteger userId)throws Exception {
          order.setUser(new User(userId," ",0000000000L," "));
          return ordersService.updateOrder(order, id);
      }
  
      @ApiOperation(value="Delete an Order")
      @RequestMapping(method = RequestMethod.DELETE, value="/orders/{id}")
      public void deleteOrder(@PathVariable BigInteger id){
          ordersService.deleteOrder(id);
      }
  
  }
  </code></pre>