title: JPA count NamedQuery
body: <p>how to get count with a namedquery, without getting all the list (it would increase performance I think). This is the named query that doesn't work:</p>
  
  <pre><code>@NamedQuery(name = "Charakteristika.findAllCount", query = "SELECT COUNT(c) FROM Charakteristika c")
  </code></pre>
  
  <p>Executing this:</p>
  
  <pre><code>System.out.println("a");
  System.out.println(em.createNamedQuery("Charakteristika.findAllCount", Integer.class).getSingleResult().intValue());
  System.out.println("b");
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>a
  </code></pre>
  
  <p>Although this query works:</p>
  
  <pre><code>@NamedQuery(name = "Charakteristika.findAll", query = "SELECT c FROM Charakteristika c")
  </code></pre>
  
  <p>Executing this:</p>
  
  <pre><code>System.out.println("a");
  System.out.println(em.createNamedQuery("Charakteristika.findAll", Charakteristika.class).getResultList().size());
  System.out.println("b");
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>a
  11111
  b
  </code></pre>