SQL 服务器,HQL:如何将 SQL 服务器日期时间列字段与日期进行比较

SQL Server, HQL: How to compare SQL server datetime column field to date

我有以下 SQL 查询,我需要使其在 HQL 中运行,我尝试了几个解决方案,但其中 none 有效。(数据库:SQL 服务器)

select t.createdTimeStamp FROM ServiceData t , UserInfo C where C.UserId = t.UserId and  CAST(t.createdTimeStamp AS DATE) = '2016-05-30'

我尝试在 HQL 中进行以下操作,但 none 成功了,(createdTimeStamp 是 sql 服务器中的日期时间数据类型)

查询:

select t.createdTimeStamp FROM ServiceData t , UserInfo C where C.UserId = t.UserId and  CAST(t.createdTimeStamp AS DATE) = '2016-05-30'

错误:

org.hibernate.QueryException: Could not resolve requested type for CAST : DATE

任何关于如何让它发挥作用的建议都会有所帮助。

我在 Whosebug 下面找到了答案 URL Whosebug-date-is-not-a-recognized-built-in-function-name

我使用 CONVERT 而不是 CAST,它起作用了

查询:select t.createdTimeStamp FROM ServiceData t , UserInfo C where C.UserId = t.UserId and CONVERT(date,t.createdTimeStamp) = '2016-05-30'

但不确定为什么 CAST 不起作用,因为 Hibernate Doc CAST 受支持

你必须按照下面的方式编写cast命令,然后它才会起作用

cast(t.createdTimeStamp as date)

所以 "cast"、"as" 和 "date" 小型大写