title: Is it possible in Hibernate to replace multiple calls with different parameters in a loop with one call?
body: <p>There is a <code>@NamedQuery</code> which counts number of <code>Person</code> with given name:</p>
  <pre class="lang-java prettyprint-override"><code> @NamedQuery(name = &quot;Person.countNames&quot;, query = &quot;SELECT count(*) FROM Person p WHERE p.name= :name&quot;)
  </code></pre>
  <p>I'm using this query in a loop to count <code>Person</code> for a specific list with names:</p>
  <pre class="lang-java prettyprint-override"><code>List&lt;String&gt; names = Arrays.asList(&quot;John&quot;, &quot;Stan&quot;, &quot;Robert&quot;);
  HashMap&lt;String, Long&gt; results = new HashMap&lt;&gt;();
  for (String name : names){
     Long count = entityManager.createNamedQuery('Person.countNames').setParameter(&quot;name&quot;, name)
     results.put(name, count);
  }
  </code></pre>
  <p>I would like to optimize this process to only call once to the database. Is it possible to create such <code>@NamedQuery</code> which will give immediate results in <code>HashMap</code> or in any other form?</p>