![](/img/trans.png)
[英]Spring Data/Hibernate native query returning null even though real query returns results
[英]JPA method not returning results even though the generated query returns results when used in postgres console
即使當我記錄查詢並在數據庫控制台上嘗試時,我也沒有得到 JPA 方法的任何結果,但我得到了正確的結果
回購:
公共接口 FireWeatherDay1CatRiskRepository 擴展
JpaRepository<FireWeatherDay1CatRisk, Long> {
List<FireWeatherDay1CatRisk> findByAdvTs(Instant advTs);
}
生成的查詢:
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';
同樣,使用 JPA 方法時沒有返回結果,但是當我在我的 postgres 控制台中手動運行查詢時,生成的查詢似乎是正確的,它工作正常。
您沒有執行相同的查詢。 JPA 執行的是最肯定的
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=?;
加上綁定值的值。
問題很可能是瞬間發生了一些轉換,可能涉及您的 JVM 或數據庫的當前時區。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.