I have a problem when making a select to a table in a database, the data resulting from it is incorrect. Can there be some kind of Spring cache to update?
@Service
public class CronogramaService {
@Autowired
private CronogramaRepository cronogramaRepository;
@Autowired
private EntityManager entityManager;
public List<Cronograma> findAll() {
QCronograma cronograma = QCronograma.cronograma;
return new JPAQuery(entityManager)
.from(cronograma)
.list(cronograma);
}
}
Test main
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring_config.xml");
CronogramaService cronoService = context.getBean(CronogramaService.class);
List<Cronograma> crono = cronoService.findAll();
for (Cronograma cronograma : crono) {
System.out.println(cronograma.getDia());
System.out.println(cronograma.getIdCronograma());
}
System.out.println();
((ClassPathXmlApplicationContext)context).close();
}
The application has 365 days of the year 2018. But the result in id 1 returns me the day 2017-12-31. In the database the data of id 1 is 01-01-2018, and I do not understand what the problem is.
We had a similar issue which boiled down to different timezones between application server and database server. Assuming you're using MySQL, try connecting to your database with the serverTimezone parameter set like jdbc:mysql://server:3306/database?serverTimezone=Europe/London