When you call PUT api, you only pass name
in the body, but the request User
type, so Spring will understand that your body is:
{
"id": null,
"name": "your_input_name",
"date_created": null
}
And in your update
method, you only copy object with id => the dateCreated
still null
.
That why when it save to db, the date_created
column is null
You can first query the object in db with id
, change name
field then save it back.
Or you can add updatable = false
to make sure date_created
will not be updated.
@Column(name= "date_created", updatable = false)