r/javahelp • • 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

13 comments sorted by

View all comments

Show parent comment

2

u/DeatH_StaRR Jul 12 '25

Figured it out - in my PROD version, I give the DB location as ${mysql.service.local.name} in the yml (45.***.***.***).
It doesn't work in the tests - I have to give it explicit IP, otherwise it goes to localhost...