Spring-data-mongodb save localdatetime with different time zone

635 views Asked by At

I have a spring boot application that uses spring-boot-starter-data-mongodb (2.7.7) to link with a local mongodb (v6). I have two different classes (with a LocalDateTime property) that maps two different collections; my problem is that the LocalDateTime property of the two classes are saved like they come from different timezone in the rispective mongo collection.

First class/collection

Class

@Document("CollectionOne")
public class ClassOne{
@Id
private String id;
private LocalDateTime dataChiamata;

Repo

public interface ClassOneRepo extends MongoRepository<ClassOne, String>{}

Saving

classOneRepo.save(obj1);

Obj1.dataChiamata ( from debugger )

enter image description here

MongoDb CollectionOne: exact same date of java
enter image description here



Second class/collection

Class

@Document("CollectionTwo")
public class ClassTwo{
@Id
private String id;
private List<LocalDateTime> giorniLetti;

Repo

public interface ClassTwoRepo extends MongoRepository<ClassTwo, String> {}

Saving

classTwoRepo .save(obj2);

Obj2.giorniLetti.get(0) (from debugger)
enter image description here

MondoDB CollectionTwo: one hour previous respect the java

enter image description here



I don't understand why the two dates are saved in a different way on the db although they are exactly the same java object; any suggestion?

0

There are 0 answers