title: How to use quote inside LIKE jpql query?
body: <p>So, I'm trying to write some custom JPQL query builder.
  I have an endpoint something like:</p>
  
  <pre><code>/api/library/authors/search?query=test tested
  </code></pre>
  
  <p>On service layer this <code>query</code> param will be transformed to smth like this JPQL query:</p>
  
  <pre><code>SELECT t FROM Author t WHERE t.fullName LIKE '%test tested%' 
       OR t.firstName  LIKE '%test%' 
       OR t.firstName  LIKE '%tested%' 
       OR t.secondName LIKE '%test%' 
       OR t.secondName LIKE '%tested%'
  </code></pre>
  
  <p>It works pretty good for me but, it is possible that <code>firstName</code> or <code>secondName</code> table columns will contain values with quote <code>'</code> like <code>O'Hara</code>. Then it won't work.</p>
  
  <pre><code>/api/library/authors/search?query=Tes O'Ha
  </code></pre>
  
  <p>So, I tried to replace <code>'</code> to double quotes <code>"</code> in query to smth like this:</p>
  
  <pre><code>SELECT t FROM Author t WHERE t.fullName LIKE "%Tes O'Ha%" 
       OR t.firstName  LIKE "%Tes%" 
       OR t.firstName  LIKE "%O'Ha%" 
       OR t.secondName LIKE "%Tes%" 
       OR t.secondName LIKE "%O'Ha%"
  </code></pre>
  
  <p>and I got an exception:</p>
  
  <pre><code>org.hibernate.QueryException: unexpected char: '"'
  </code></pre>
  
  <p>I also tried to replace <code>'</code> on <code>\'</code> and <code>"</code> on <code>\"</code>. All it not works and throws me an exception...</p>
  
  <p>I'm executing this queries using EntityManager:</p>
  
  <pre><code>@Repository
  public class SearchFor {
      @PersistenceContext
      private EntityManager entityManager;
  
      public List execute(String query) {
          return entityManager.createQuery(query).getResultList();
      }      
  }
  </code></pre>
  
  <p>How can I search for value that contains single quote <code>'</code>?</p>