title: java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of string that does not exist in the query string
body: <p>I have the following named query:</p>
  
  <pre><code>@NamedQuery(
      name = "Userdetails.findByUsername", 
      query = "SELECT u FROM Userdetails u WHERE u.username = :username"
  )
  </code></pre>
  
  <p>When I try to execute it as follows:</p>
  
  <pre><code>getEntityManager()
      .createNamedQuery("Userdetails.findByUsername")
      .setParameter("string", "%" + string + "%")
      .getResultList();
  </code></pre>
  
  <p>Then I get the following exception:</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of string that does not exist in the query string SELECT u FROM Userdetails u WHERE u.username = :username.</p>
  </blockquote>
  
  <p>How is this caused and how can I solve it?</p>