2

How can I use date_sub() function in hql. For Example following in sql query: select * FROM performance where performance_id= 8955 and daterangefrom >= (date_sub('2008-12-01 00:00:00',interval 8 hour));

I have to write this in @NamedQuery, so I tried this but not working:

@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' ")
Sachin J
  • 2,081
  • 12
  • 36
  • 50

1 Answers1

2

I met the same problem with you, It seems that hibernate dosn't support mysql function of DATE_SUB, so we have to use the native sql query

Hunter Zhao
  • 4,589
  • 2
  • 25
  • 39