Hibernate 如何在HQL中使用Date_sub()函数?
如何在hql中使用date_sub()函数。 例如,sql查询中的以下示例: 选择*FROM performance,其中performance_id=8955,daterangefrom>=(date_sub('2008-12-01 00:00:00',间隔8小时)) 我必须在@NamedQuery中编写此代码,因此我尝试了此操作,但没有成功:Hibernate 如何在HQL中使用Date_sub()函数?,hibernate,hql,Hibernate,Hql,如何在hql中使用date_sub()函数。 例如,sql查询中的以下示例: 选择*FROM performance,其中performance_id=8955,daterangefrom>=(date_sub('2008-12-01 00:00:00',间隔8小时)) 我必须在@NamedQuery中编写此代码,因此我尝试了此操作,但没有成功: @NamedQuery(name = "performance.performanceBySourceId", query = "select p f
@NamedQuery(name = "performance.performanceBySourceId", query = "select p from Performance p where p.source.id = :sourceID and p.dateRangeFrom >= (registerFunction('performance.queryString', new SQLFunctionTemplate(Hibernate.STRING, 'date_add('2008-12-01 00:00:00', INTERVAL 2 hour))) order by p.dateRangeFrom desc' ")
我也遇到了同样的问题,hibernate似乎不支持DATE_SUB的mysql功能,所以我们不得不使用原生sql查询