title: Querydsl generates invalid SQL on basic aggregate query
body: <p>I am using QueryDSL and Hibernate to query a SqlServer2008 database.</p>
  
  <p>I have a Sessions table that contains a sessionId column. I want to obtain the max sessionId.</p>
  
  <p>I run the following query:</p>
  
  <pre><code>QSessions session = QSessions.sessions;
  HibernateSQLQuery query = new HibernateSQLQuery(sessionFactory.openSession(), new SQLServer2005Templates());
  query.from(session).list(session.sessionId.max());
  </code></pre>
  
  <p>My hibernate.cfg.xml:</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:sqlserver://SVR;databaseName=DB&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;X&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;X&lt;/property&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;com.microsoft.sqlserver.jdbc.SQLServerDriver&lt;/property&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.SQLServer2008Dialect&lt;/property&gt;
  
          &lt;mapping class="com.coveo.data.Sessions" /&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>When I run the query, I can see that Hibernate attempts to run the following SQL query:</p>
  
  <pre><code>17:36:10.011 [main] DEBUG org.hibernate.SQL - select max(sessions.*.sessionId) as col__1 from sessions
  </code></pre>
  
  <p>This is not valid SQL. I would have expected </p>
  
  <pre><code>select max(sessions.sessionId) as col__1 from sessions
  </code></pre>
  
  <p>When Hibernate attempts to execute the query, I get the following error:</p>
  
  <pre><code>com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '*'.
  </code></pre>
  
  <p>I get the same syntax error when attempting to run the invalid SQL query using SQL Management Studio.</p>
  
  <p>Why does Querydsl require a dialect? Isn't Hibernate in charge of generating the SQL?</p>
  
  <p><strong>Why is the generated SQL invalid?</strong></p>
  
  <p>EDIT: I get the same behavior when using .avg(), .min() or another aggregate function.</p>