title: Finding the Max of Select Query
body: <p>I am new developer for JPA and have a assignment to write the retrieve records from database using JPQL. Below is my Query. Basically I am trying to find the max of field1 from table Z.</p>
  
  <pre><code>SELECT X.Id,        
       MAX (
          NVL (
             (SELECT field1
                FROM table Z
               WHERE  X.Id = Z.id.Id),'')) field
  FROM table1 X, table2 Y
  WHERE X.Id = Y.Id
  group by X.Id
  </code></pre>
  
  <p>While Executing this query I am getting the error as below</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: 'NVL' {originalText=NVL}
     \-[EXPR_LIST] SqlNode: 'exprList'
  </code></pre>
  
  <p>Please Advise. When I am running the query using normal sql, its working fine.</p>