title: JPA: How to perform a LIKE with a NUMBER column in a static JPA MetaModel?
body: <p>I do have a static metamodel with a NUMBER (actually, BigDecimal, don't ask why) column. Now I would like to do a LIKE query against that number column:</p>
  
  <pre><code>CriteriaBuilder cb;
  cb.like(entity.get(Entity_.numbercol), "123%");
  </code></pre>
  
  <p>where <code>entity.get(Entity_.numbercol)</code> returns a <code>Path&lt;BigDecimal&gt;</code>. Naturally, I get a compile error: <code>...like(Expression&lt;String&gt;, ...) ... not applicable for the arguments (Path&lt;BigDecimal&gt;, ...)</code></p>
  
  <p>Casting the column with <code>.as(String.class)</code> fails due to some Bug in JPA, but I don't have the bug number at hands right now. It is not fixed in the latest version of JPA/Hibernate, though. Anyway, it results in a runtime exception about some invalid SQL statement being generated.</p>
  
  <p>Now I just need a way to get the criteria API equivalent of the SQL</p>
  
  <pre><code>... WHERE numbercol LIKE '123%';
  </code></pre>
  
  <p>Searching for the topic already brought up the following responses, which don't help because I have a static metamodel:
  <a href="https://stackoverflow.com/questions/1231054/nhibernate-easiest-way-to-do-a-like-search-against-an-integer-column-with-crit">NHibernate - easiest way to do a LIKE search against an integer column with Criteria API?</a> and <a href="https://stackoverflow.com/questions/4014390/jpa-criteria-api-like-equal-problem">JPA/Criteria API - Like &amp; equal problem</a></p>
  
  <p>Any ideas?</p>
  
  <p>Thanks in advance
  Dominik</p>