title: In Spring Boot with JPA, how do I configure my application so that a date column auto-populates with the current time of it's creation?
body: <p>I'm using Spring Boot 2 with Java 11.  I have created the following JPA entity ...</p>
  <pre><code>@Entity
  @Table(name = &quot;Mailings&quot;)
  public class Mailing {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private UUID id;
      
      @ManyToOne
      @NotNull
      private Card card;
      
      private String message;
      
      @Column(columnDefinition=&quot;TIMESTAMP DEFAULT CURRENT_TIMESTAMP&quot;)
      private java.sql.Timestamp mailingDate;
      
      @OneToOne(cascade = CascadeType.ALL)
      @NotNull
      private Address senderAddress;
      
      @OneToOne(cascade = CascadeType.ALL)
      @NotNull
      private Address recipientAddress;
  }
  </code></pre>
  <p>This is correctly created in my PostGres 10 database when I start my development application ...</p>
  <pre><code>cardmania=# \d mailings;
                        Table &quot;public.mailings&quot;
          Column        |            Type             |   Modifiers   
  ----------------------+-----------------------------+---------------
   id                   | uuid                        | not null
   creation_date        | timestamp without time zone | default now()
   message              | character varying(255)      | 
   card_id              | uuid                        | not null
   recipient_address_id | uuid                        | not null
   sender_address_id    | uuid                        | not null
  Indexes:
      &quot;mailings_pkey&quot; PRIMARY KEY, btree (id)
  Foreign-key constraints:
      &quot;fk5hy4mbv0ewd82t5b8b7shaxkc&quot; FOREIGN KEY (sender_address_id) REFERENCES addresses(id)
      &quot;fk67j1xe6kw5510en1daylstnnn&quot; FOREIGN KEY (card_id) REFERENCES cards(id)
      &quot;fknwiu32uusnxegnulcj1di158k&quot; FOREIGN KEY (recipient_address_id) REFERENCES addresses(id)
  </code></pre>
  <p>Then I created this controller to handle POST requests ...</p>
  <pre><code>@RestController
  @RequestMapping(&quot;/api/mailing&quot;)
  public class MailingController {
  
      @Autowired
      private MailingService mailingService;
      
      @PostMapping
      @ResponseStatus(code = HttpStatus.CREATED)
      public void create(@Valid @RequestBody Mailing mailing) {
          mailingService.save(mailing);
      }
      
  }
  </code></pre>
  <p>However one issue I am facing is that when I submit POST requests with JSON like the below</p>
  <pre><code>{
    &quot;senderAddress&quot;: {
      &quot;name&quot;: &quot;Joe Recipient&quot;,
      &quot;city&quot;: &quot;Los Angeles&quot;,
      &quot;state&quot;: &quot;California&quot;,
      &quot;zip_code&quot;: &quot;60615&quot;,
      &quot;street&quot;: &quot;555 Hello Way&quot;
    },
    &quot;recipientAddress&quot;: {
      &quot;name&quot;: &quot;Joe Recipient&quot;,
      &quot;city&quot;: &quot;Los Angeles&quot;,
      &quot;state&quot;: &quot;California&quot;,
      &quot;zip_code&quot;: &quot;60615&quot;,
      &quot;street&quot;: &quot;555 Hello Way&quot;
    },
    &quot;card&quot;: {
      &quot;id&quot;: &quot;05b7af7c-1de5-4a72-aebf-4c9e4d9acec3&quot;
    },
    &quot;message&quot;: &quot;Hi&quot;
  }
  </code></pre>
  <p>The entity is created correctly in my database but the &quot;creation_date&quot; field is null instead of populating with the current timestamp.  Note that the column was generated with a &quot;default now()&quot; modifier, so what else do I need to do in order for my timestamp column to populate properly?</p>