title: NamedQueries Spring using LIKE % %
body: <p>I just want to code a simple search engine.</p>
  
  <p>In my DAO implementation :</p>
  
  <pre><code>@Transactional(readOnly=true)
      public List&lt;Thread&gt; findAllWithReferer(String referer) {
          Map&lt;String, Object&gt; params = new TreeMap&lt;String, Object&gt;();
  
          log.debug("DAO:findAllWithReferer(String referer) - referer=" + referer);
          params.put("referer", "%" + referer + "%");
          @SuppressWarnings("unchecked")
          List&lt;Thread&gt; threads = EntityManagerUtil.executeNamedQueryInTransaction("Thread.findAllWithReferer", params);
          return (threads);
      }
  </code></pre>
  
  <p>Utils class providing the method 'executeNamedQueryInTransaction' above:</p>
  
  <pre><code>@SuppressWarnings("rawtypes")
      public static List executeNamedQueryInTransaction(String queryName, Map&lt;String, Object&gt; params) {
          EntityManager em = createEntityManagerAndOpenTransaction();
          Query query = em.createNamedQuery(queryName);
  
          for (String key : params.keySet())
              query.setParameter(key, params.get(key));
  
          List l = query.getResultList();
          commitTransactionAndCloseEntity(em);
  
          return l;
      }
  </code></pre>
  
  <p>And the Namedquery linked to my entity :</p>
  
  <pre><code>@NamedQueries({
      @NamedQuery(name = "Thread.findAllWithReferer", query = "SELECT t FROM Thread t WHERE t.title LIKE :referer")
  })
  </code></pre>
  
  <p>I just want to match all records with, for exemple, the string 'toto' in my entity title field using the operator % % in my DAO.</p>
  
  <p>Here's some exemple that could match :</p>
  
  <p>toto is great
  Doestotois great ?
  dghjgdjtotojdashkjdhk</p>
  
  <p>But it does not work. Just the exact string works.
  I want to precise that the code into 'executeNamedQueryInTransaction' method is correct and works perfectly. I think my problem comes from here :</p>
  
  <pre><code>params.put("referer", "%" + referer + "%");
  </code></pre>
  
  <p>Does anyone can help me, please ?
  Thanks in advance for your help.</p>