JPA method not returning results even though the generated query returns results when used in postgres console

Viewed 44

I'm not getting any results for JPA method even though when i log the query and try it on the database console i get the correct results

REPO:

public interface FireWeatherDay1CatRiskRepository extends

JpaRepository<FireWeatherDay1CatRisk, Long> {
    List<FireWeatherDay1CatRisk> findByAdvTs(Instant advTs);
}

GENERATED QUERY:

select fireweathe0_.id as id1_0_,
       fireweathe0_.adv_ts as adv_ts2_0_,
       fireweathe0_.category as category3_0_,
       fireweathe0_."end" as end4_0_,
       fireweathe0_.geom as geom5_0_,
       fireweathe0_.start as start6_0_
from fire_weather_day1_cat_risk fireweathe0_
    where fireweathe0_.adv_ts='2021-09-28T17:00:00Z';

Again, no results return when using the JPA method, but the query generated seems to be correct when i manually run the query in my postgres console it works fine.

1 Answers

You are not executing the same query. What JPA is executing is most certainly

select fireweathe0_.id as id1_0_,
       fireweathe0_.adv_ts as adv_ts2_0_,
       fireweathe0_.category as category3_0_,
       fireweathe0_."end" as end4_0_,
       fireweathe0_.geom as geom5_0_,
       fireweathe0_.start as start6_0_
from fire_weather_day1_cat_risk fireweathe0_
    where fireweathe0_.adv_ts=?;

plus a value for the bind value.

The problem is most likely that some conversion happens to the instant, probably involving the current timezone of your JVM or of the database.

Related