title: hibernate parameter with that name [<name>] did not exist
body: <p>I am running the following code.</p>
  
  <p>UserService.java</p>
  
  <pre><code>String alias = "u";
  String select = "SELECT u.email";
  String where = "u.userId = :id";
  Map&lt;String, Object&gt; params = new HashMap&lt;&gt;();
  params.put("id", userId);
  
  List&lt;User&gt; users = db.findRecords(User.class, alias, select, where, params);
  </code></pre>
  
  <p>DB.java</p>
  
  <pre><code>public &lt;T&gt; List&lt;T&gt; findRecords(Class&lt;T&gt; entityClass, String entityAlias, String select, String where, Map&lt;String, Object&gt; params) {
      String sql = select + " FROM " + entityClass.getName() + " " + entityAlias;
  
      if (where != null) {
          sql = sql + " WHERE " + where;
      }
  
      Query query = entityManager.createQuery(sql);
      System.out.println(sql);
      if (!params.isEmpty()) {
          Iterator&lt;Entry&lt;String, Object&gt;&gt; iterator = params.entrySet().iterator();
          while (iterator.hasNext()) {
              Entry&lt;String, Object&gt; entry = iterator.next();
              System.out.println("key: " + entry.getKey() + ", value: " + entry.getValue());
              query.setParameter((String) entry.getKey(), (Long) entry.getValue());
          }
      }
  
      return query.getResultList();
  }
  </code></pre>
  
  <p>I am getting the following error log.</p>
  
  <pre><code>SELECT u.email FROM com.catalog.user.User u WHERE u.userId = :id
  key: id, value: 28636907
  
  Caused by: java.lang.IllegalArgumentException: Parameter with that name [id] did not exist
  </code></pre>
  
  <p>If the parameter is getting printed in the console then what is causing the illegal arguments exception to come up?</p>
  
  <p>Please help!</p>