LocalDate JPA repository strange "feature"

148 Views Asked by At

Here is the RequestBody as JSON in SpringBoot RestController

{
    "birthdate": "1991-09-30"
}

Entity:

class MyEntity {
    private LocalDate birthdate;
}

JPA Repository:

public interface MyEntityRepository extends JpaRepository<MyEntity, Integer> {}

Saving entity:

myEntity.setBirthdate(LocalDate.parse(dateTime, DateTimeFormatter.ofPattern("yyyy-MM-dd")));

Problem: Working fine dates after 1991-09-30 and saved as it is. But dates before this are saved as one day before.
For example, dates before subtracting one day

{
    "birthdate": "1991-09-29"
}

enter image description here

PS.

I'm using mysql Ver 8.0.21-0ubuntu0.20.04.4 for Linux on x86_64 ((Ubuntu))

enter image description here

I'm using Ubuntu 20.04:
enter image description here

1

There are 1 best solutions below

0
On

try using Date this is just example :

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