title: javax.persistence.NoResultException: getSingleResult() did not retrieve any entities
body: <p>i have created a namedquery with ejb to check if the username is used.
  When the singleResult is null, then i get the following Exception :</p>
  
  <pre><code>javax.persistence.NoResultException: getSingleResult() did not retrieve any entities
  </code></pre>
  
  <p>But this exception is the result that i want when the username is free. </p>
  
  <p>Here is the code:</p>
  
  <pre><code> public User getUserByUsername(String username) throws DAOException{
      try{
          Query q = em.createNamedQuery(User.getUserByUsername);
          q.setParameter("username", username);
          return (User) q.getSingleResult();
      }catch(Exception e){
          throwException(username, e);
          return null;
      }
  }
  </code></pre>
  
  <p>Does anybody know what the problem is. :(</p>
  
  <p>I would like to return null and don`t get an Exception.</p>
  
  <p>Thank you very much</p>