I want to sign jwt token with LocalDateTime
which is received after creating the user. After that, I need to check if jwt is valid and I'm achieving that with date retrieved from DB.
Problem is that LocalDateTime
on creation contains nanoseconds, and date from DB does not, and then the validation fails.
I try to resolve this with formating LocalDateTime
to display date without nanoseconds, but there is another problem. LocalDateTime
is rounded to floor (e.g 1.222 is 1, and 1.777 is 1) and date inserted in DB is rounded like this 1.222 is 1, 1.777 is 2, so validation again fails.
I manage to resolve this by adding @Column(columnDefinition = "TIMESTAMP (6)")
on my field in entity and now nanoseconds are also stored in DB, and everything works, but I'm not sure that this is the right solution.
So is there any better solution? Can I somehow round LocalDateTime
same as in DB(and leave db field type as DATETIME
and not TIMESTAMP
) or can DB date be rounded as LocalDateTime
.
I'm using spring boot 2.2.4