jpa 中在Repository中将Date类型作为入参进行查询,查询不到结果?

@Query("select t from PartialDischargeForecast t where t.monitoringName =?1 and t.futureTime = ?2")
List<PartialDischargeForecast> queryByName(String name,Date date);

jpa中这样一句把时间作为参数传入作条件查询时,返回没有结果。查看后台的sql日志,输出的sql又是正确的。

并且将后台打印该方法执行的sql直接放在数据库中执行时,又能查询到数据,奇怪!

 

原因不明。不过解决办法倒是有,在方法定义入参时,给时间类型的参数加上注解 @Temporal(TemporalType.TIMESTAMP),进行查询即可生效

@Query("select t from PartialDischargeForecast t where t.monitoringName =?1 and t.futureTime = ?2")
List<PartialDischargeForecast> queryByName(String name,@Temporal(TemporalType.TIMESTAMP) Date date);

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章