title: Convert SQL statement 'LIKE' to JPQL statement
body: <p>I want to write this SQL statement in eclipse JPQL query. It works in SQL but I'm not sure how to write it in eclipse.</p>
  
  <pre><code>SELECT * 
  FROM hardware h
  WHERE h.`Staffid` LIKE '%150%'
  </code></pre>
  
  <p>My staffid in hardware table is a foreign key to staff table's staffid primary key. So the staff in the hardware table is </p>
  
  <pre><code>private Staff staff;
  </code></pre>
  
  <p>This is what I write to run my search:</p>
  
  <pre><code>@SuppressWarnings("unchecked")
  public List&lt;Hardware&gt; searchstaff(Staff a) {
      try {
          entityManager.getTransaction().begin();             
  
          Query query = entityManager
              .createQuery("SELECT st from Hardware st where st.staff LIKE :x");
          query.setParameter("x", a);
  
          List&lt;Hardware&gt; list = query.getResultList(); 
          entityManager.getTransaction().commit();         
          return list;                     
      } catch (Exception e) {
          return null;
      }
  }
  </code></pre>
  
  <p>But it shows </p>
  
  <pre><code>javax.servlet.ServletException: java.lang.IllegalStateException: 
  Exception Description: Transaction is currently active 
  </code></pre>
  
  <p>when I run the search.</p>
  
  <p>Can anyone help me correct?</p>