title: Get generic object from hibernate query
body: <p>As described in <a href="http://www.javacodegeeks.com/2012/07/ultimate-jpa-queries-and-tips-list-part_7092.html" rel="nofollow">http://www.javacodegeeks.com/2012/07/ultimate-jpa-queries-and-tips-list-part_7092.html</a>, you can get objects from a jpa query.
  So far, so good.</p>
  
  <p>But since I will have to use this quite often, I want to use generics.
  So instead of</p>
  
  <pre><code>Query query = em.createQuery('select new com.model.PersonDogAmountReport(p, size(p.dogs)) from Person p');
  </code></pre>
  
  <p>I want</p>
  
  <pre><code>Query query = em.createQuery('select new com.model.Report&lt;Person, Long&gt;(p, size(p.dogs)) from Person p');
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Query query = em.createQuery('select new com.model.Report&lt;com.model.Person, java.lang.Long&gt;(p, size(p.dogs)) from Person p');
  </code></pre>
  
  <p>. Trying this gives me the following exception:</p>
  
  <pre><code>org.hibernate.hql.ast.QuerySyntaxException: expecting OPEN, found '&lt;' near line 1
  </code></pre>
  
  <p>Does this mean, that what I want is just not supported?
  Are there good alternatives?</p>
  
  <p>Nearly the same thing is possible with <em>NamedNativeQuery</em> and <em>resultClass</em>, but that way I wouldn't get Person as an entity.</p>
  
  <p>If I use object instead, the returned List cannot be cast, meaning I have to iterate -> meh desu.</p>
  
  <p>Thanks in advance for any help.</p>