Hibernate SQL查询仅比较时间戳字段中的日期

时间:2019-06-25 14:43:52

标签: java mysql hibernate date

我必须从mysql DB获取基于last_update_At的记录列表。它是mysql中的timestamp字段。从我的Java代码中以以下格式传递日期。

 Mon May 06 20:05:32 IST 2019

在mysql last_update_At中,格式为2019-05-06 19:46:00。我只想在日期比较中获取此记录,而不是与时间有关。

请在下面找到我的休眠查询:

 @Query("select u from User u where u.lastLoginAt <= :thresholdDate")
 public List<User> findLastLoginDaysDifference(@Param("thresholdDate") Date thresholdDate);

使用此查询无法获取记录。

1 个答案:

答案 0 :(得分:0)

您可以使用Hibernate强制转换运算符:

select u from User u where cast(u.lastLoginAt as date) <= :thresholdDate