-1
I’m having a little, boring problem that I can’t seem to solve.
I am making a java application using Spring Framework and using Vuejs as front. The database is Mysql.
The problem is that when I try to save a date equal to or earlier than 02/16/2019, the date is saved with 1 day less in Mysql. If it is a later date, the date is saved correctly.
Edit: I realized that in the year 2020 also occurs this problem, seems to be something related to this period from 01/01 to 16/02.
edit2: I noticed that the problem starts in November, from 05/11. That is, any date I try to save between 05/11 and 16/02, is saved in the bank with the previous day. If not in that period, the date is normally saved.
I have already confirmed that the date arrives correctly in java, so the problem is not in Vuejs. And I also found that before making the call to save the entity through Jparepository, the date is still correct, so I think it’s a problem in Mysql, or some configuration that needs to be done in Spring.
I already tweaked the Spring properties file settings using these properties:
- spring.jpa.properties.hibernate.jdbc.time_zone=America/Sao_paulo
- user.Timezone=America/Sao_paulo
But none of them solved the problem.
Can anyone help me out there? VLW!
Put the code snippet q saves the date in pfvr database.
– dferreira
I use the Jparepository save() method, and my entity has a Localdate type parameter and in Mysql the field is Date type. I don’t do any treatment before calling save() from Jparepository, I take the object the way it comes from the front and send it to Jparepository.
– Paulo Motta
In this case it would be this: Return Repository.save( member ); Note: This object returned by Jparepository is with the correct date, but in the saved bank with the date -1
– Paulo Motta
Do you use any Date notes in your class? As far as I know there are two possible ones, @Temporal(Temporaltype.DATE) and @Temporal(Temporaltype.TIMESTAMP). Take a look at this link and try to format it before going to the bank to see if it solves.https://www.baeldung.com/hibernate-date-time
– dferreira
This link you sent me says that the classes in the java.time. * package do not require annotation. I am using Localdate.
– Paulo Motta
When I used the Ibernate I didn’t use the util. Date and everything went well. Would it be quiet for you to test with Calendar? @Temporal(value=Temporaltype.DATE) private Calendar dataNascimento;
– dferreira
If it is difficult for you to use Calendar, use Date with the above annotation to test.
– dferreira
I think I got it. I found these two parameters to put in the BD connection string: useTimezone=true&serverTimezone=America/Sao_paulo. And I also used properties user.Timezone=America/Sao_paulo in Spring properties.
– Paulo Motta