title: Java + JPA: Search User in Database By first and last name return too many results. Is there a better way?
body: <p>Right now my implementation is like this, so if the user type is <code>Peter Smith</code>, then I would a split on the query string like this:</p>
  
  <pre><code>String[] name = searchQuery.split(" "); //searchQuery is type String
  </code></pre>
  
  <p>then I would loop through <code>name array</code>, and for each <code>name</code>, I match it against first name and last name fields in my db as below</p>
  
  <pre><code>@NamedQuery(name="User.findUserByName",
      query="select c from User c where c.fname LIKE :param OR c.lname LIKE :param"),
  
  public List&lt;User&gt; findUser(String searchParam){
      Query query = em.createNamedQuery("User.findUserByName");
      query.setParameter("param", "%" + searchParam + "%");
      return query.getResultList();
  }
  </code></pre>
  
  <p>however, if I do this, it return too many results (Every thing related to Peter will be display and everything related to Smith will be as well). Is there a better way to do this?</p>
  
  <p>I am using EclipseLink btw</p>