title: JPA: Predicate and expression both in QueryCriteria where clause
body: <p>I have a situation where in my where clause I have single predicate and expression. And both needs to be ANDed in where clause:</p>
  
  <pre><code>Expression&lt;String&gt; col1 = tableEntity.get("col1");
  Expression&lt;String&gt; regExpr = criteriaBuilder.literal("\\.\\d+$");
  Expression&lt;Boolean&gt; regExprLike = criteriaBuilder.function("regexp_like", Boolean.class, col, regExpr);
  
  Expression&lt;TableEntity&gt; col2= tableEntity.get("col2");
  Predicate predicateNull = criteriaBuilder.isNull(col2);
  
  createQuery.where(cb.and(predicateNull));
  createQuery.where(regExprLike);
  </code></pre>
  
  <p>In this case I am not able to do something like:
  createQuery.where(predicateNull, regExprLike);</p>
  
  <p>I tried using CriteriaBuilder's isTrue() method:</p>
  
  <pre><code>Predicate predicateNull = criteriaBuilder.isNull(col2);
  Predicate predicateTrue = criteriaBuilder.isTrue(regExprLike);
  createQuery.where(predicateNull, predicateTrue);
  </code></pre>
  
  <p>But it didnt help.</p>
  
  <p>CriteriaQuery either allows predicates or expressions, but not both, in where clause. any idea how can I use both, predicates and expression in QueryCriteria's where clause?</p>
  
  <p><strong><em>Update 10 Oct 2014:</em></strong>
  <strong>As suggested by Chris, I tried to use:</strong></p>
  
  <pre><code>createQuery.where(predicateNull, regExprLike);
  </code></pre>
  
  <p>But my query fails with exception:</p>
  
  <pre><code>Caused by: org.jboss.arquillian.test.spi.ArquillianProxyException: org.hibernate.hql.internal.ast.QuerySyntaxException : unexpected AST node: ( near line 1, column 311 [select coalesce(substring(generatedAlias0.col1,0,(locate(regexp_substr(generatedAlias0.col1, :param0),
  generatedAlias0.col1)-1)), generatedAlias0.col1), generatedAlias0.col1 
  from com.temp.TableEntity as generatedAlias0 
  where (generatedAlias0.col2 is null ) and ( regexp_like(generatedAlias0.col1, :param1))] [Proxied because : Original exception not deserilizable, ClassNotFoundException]
  </code></pre>
  
  <p>My code looks like:</p>
  
  <pre><code>CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
  CriteriaQuery&lt;Object[]&gt; createQuery = criteriaBuilder.createQuery(Object[].class);
  
  Root&lt;TableEntity&gt; tableEntity = createQuery.from(TableEntity.class);
  
  Expression&lt;String&gt; path = tableEntity.get("col1");
  
  Expression&lt;String&gt; regExpr = criteriaBuilder.literal("\\.\\d+$");
  Expression&lt;String&gt; regExprSubStr = criteriaBuilder.function("regexp_substr", String.class, path, regExpr);
  
  Expression&lt;Boolean&gt; regExprLike = criteriaBuilder.function("regexp_like", Boolean.class, path, regExpr);
  
  
  Expression&lt;Integer&gt; l3 = criteriaBuilder.locate(path, regExprSubStr);
  Expression&lt;Integer&gt; minusOne = criteriaBuilder.literal(1);
  Expression&lt;Integer&gt; l3Sub1 = criteriaBuilder.diff(l3, minusOne);
  Expression&lt;Integer&gt; zeroIndex = criteriaBuilder.literal(0);
  Expression&lt;String&gt; s3 = criteriaBuilder.substring(path, zeroIndex, l3Sub1);
  
  Expression&lt;TableEntity&gt; col1 = tableEntity.get("col1");
  Expression&lt;TableEntity&gt; col2 = tableEntity.get("col2");
  
  Expression&lt;String&gt; coalesceExpr = criteriaBuilder.coalesce(s3, path);
  createQuery.multiselect(coalesceExpr, col1);
  
  Predicate predicateNull = criteriaBuilder.isNull(col2);
  
  createQuery.where(criteriaBuilder.and(predicateNull, regExprLike));
  String query = entityManager.createQuery(createQuery).unwrap(org.hibernate.Query.class).getQueryString();
  </code></pre>