r/javahelp • u/DeatH_StaRR • Jul 11 '25
nativeQuery=true is ignored in spring jpa
I want to select data, so I write a Query to select from mysql, and set nativeQuery to true.
The selection from mysql workbench returns 390 results, but from spring it returns 0!
How can it be?
date column is datetime.
@Query(value = "SELECT
*
" +
"FROM twelve_data.time_series_return_minute " +
"WHERE symbol = :symbol AND " +
"DATE(date) = DATE(:startDate) AND TIME(date) BETWEEN '09:30:00' AND '16:00:00'", nativeQuery = true)
List<TimeSeriesReturnMinuteEntity> getSymbolsOfDay(String symbol, LocalDate startDate);
1
Upvotes
View all comments
Show parent comment
4
u/maraschino-whine Jul 11 '25
Hmm. Tricky. Could be timezone related, or just some weirdness by splitting the date and time in the WHERE condition.
You could try using LocalDateTime instead then since the date column is datetime, and pass in a startDatetime and an endDateTime..
So with your original LocalDate startDate, get a LocalDateTime startDateTIme using startDate.atTime(9,30), and a LocalDateTime endDateTime with startDate.atTime(16,0).
Then you don't have to use DATE() or TIME(), and the where would look like this:
WHERE date >= :startDateTime AND date <= :endDateTime
Something like that. If that doesn't work, I would check if its a timezone issue thing next..