title: Agregate Functions MAX and AVG are not working with DATEDIFF in Hibernate HQL
body: <p>I am using Hibernate3, trying to execute following HQL query, it is giving below errors.</p>
  
  <p>Query: <code>select MAX(DATEDIFF(SECOND, startTime, endTime)) from Service_Master</code></p>
  
  <pre><code>java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.AggregateNode 
  +-[AGGREGATE] AggregateNode: 'MAX'
  |  \-[METHOD_CALL] MethodNode: '('
  |     +-[METHOD_NAME] IdentNode: 'DATEDIFF' {originalText=DATEDIFF}
  |     \-[EXPR_LIST] SqlNode: 'exprList'
  |        +-[IDENT] IdentNode: 'SECOND' {originalText=SECOND}
  </code></pre>
  
  <p>Query: <code>select AVG(DATEDIFF(SECOND, startTime, endTime)) from Service_Master</code></p>
  
  <pre><code>java.lang.NullPointerException
  at org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions$AvgFunction.determineJdbcTypeCode(StandardAnsiSqlAggregationFunctions.java:98)
  at org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions$AvgFunction.render(StandardAnsiSqlAggregationFunctions.java:92)
  at org.hibernate.hql.ast.SqlGenerator.endFunctionTemplate(SqlGenerator.java:214)
  </code></pre>
  
  <p>I tried lot of ways to solve this issue, used custom dialect and added function definition to DATEDIFF and MAX functions using SQLFunction in constructor, used SQL CAST function, etc.., still it is not working...
  It is urgent requirement, please can any one answer this or re-direct me to a link where i can get solution for this.</p>