title: How to write search query in hibernate
body: <p>I was trying to write a search query in hibernate. I took help from open-meeting source code. 
  So my query: </p>
  
  <pre><code>public User getAllUser(String search) {
      String[] searchItems = search.split(" ");
      try {
          String sqlQuery = "SELECT * FROM  USER u " + "WHERE u.deleted = 1 ";
          sqlQuery += "AND ( ";
          for (int i = 0; i &lt; searchItems.length; i++) {
              if (i != 0) {
                  sqlQuery += " OR ";
              }
              sqlQuery += "( " + "lower(u.last_name) LIKE '"
                      + StringUtils.lowerCase("%" + searchItems[i] + "%")
                      + "' " + "OR lower(u.first_name) LIKE '"
                      + StringUtils.lowerCase("%" + searchItems[i] + "%")
                      + "' " + "OR lower(u.username) LIKE '"
                      + StringUtils.lowerCase("%" + searchItems[i] + "%")
                      + "' " + ") ";
          }
          sqlQuery += " )";
  
          log.debug("sqlQuery : " + sqlQuery);
          Query query = sessionFactory.getCurrentSession().createQuery(
                  sqlQuery);
  
          return (User) query.list().get(0);
  
      } catch (HibernateException e) {
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>
  
  <p>It says there is an unexpected token, I but I didn't find where it is. </p>
  
  <p><strong>So I have two questions:</strong></p>
  
  <ol>
  <li>how to make it functional.</li>
  <li>how to write search query using Criteria and Projection/Restrictions in hibernate </li>
  </ol>