Hardik Lotiya Hardik Lotiya - 29 days ago 11x
Java Question

Hibernate : convert mysql Query Datedif to HQL Query

here is my Query in mysql

SELECT DATEDIFF('2008-11-30','2008-11-29') AS DiffDate

how to convert in to Hibernate Query Language


One of the way you can achieve this by extending mysql dialect and register it using registerFunction(String, SQLFunction)

public class CustomMySQL5InnoDBDialect extends MySQL5InnoDBDialect {

  public CustomMySQL5InnoDBDialect () {
    registerFunction( "datediff", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "datediff(?1, ?2)" ) );