如何在 hql 中使用 date_sub() 函数。例如以下sql查询:select * FROM performance where performance_id= 8955 and daterangefrom >= (date_sub('2008-12-01 00:00:00',interval 8 hour));
我必须在@NamedQuery 中写这个,所以我尝试了这个但没有工作:
@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' ")