Ankur Singhal
Ankur Singhal

Reputation: 26067

@Temporal - DateFormat - JPA

I am using below in my Customer entity to map Date field

@Temporal(TemporalType.DATE)
@Column(name = "birthdate")
@DateTimeFormat(pattern = "dd-MM-yyyy")
private Date birthDate;

But still BirthDate is saved in yyyy-MM-dd format. I have tried setting in setter method for field birthDate using DateFormat, but still same response.

Database is Mysql, column is of type Date. I wish to set the value in dd-MM-yyyy format.

Upvotes: 1

Views: 15762

Answers (1)

roxch
roxch

Reputation: 351

As far as I know from former project, this is the given date format in MySQL and can't be changed so straight forward. I would set the date pattern in mapping the same as in databank (YYYY-MM-DD) and reformat it later in the usage.

Upvotes: 1

Related Questions