title: Persistance's CriteriaBuilder - check if greater than 0
body: <p>I gave up trying to figure it out so I ask here :) my goal is to filter some data in database query by CriteriaBuilder. Each <code>Client</code> has fields like <code>howMuchOrders</code> and <code>orderTotalValue</code>.</p>
  
  <p>Here I try to check if my given <code>atLeastAverageValue</code> is lower than <code>averageTotalValueExpression</code>(calculated by dividing <code>orderTotalValue</code> by <code>howMuchOrders</code>). At very begining I need to check if my <code>atLeastAverageValue</code> is not null. Otherwise I do not want to add predicate to list of executed predicates with query.</p>
  
  <p>Everything works fine until <code>root.get("orderCount")</code> gives zero (which is possible) and it throws <code>org.springframework.dao.DataIntegrityViolationException</code>. I could catch and handle this exception, but it is not the way i like to do it. Firstly I'd like to check if value in <code>root.get("orderCount")</code> is not null. If it is not - calculate and add prediacte to predicates list. Otherwise do nothing.</p>
  
  <pre><code>private void addMaxAveragePredicate(BigDecimal atLeastAverageValue, List&lt;Predicate&gt; predicates, CriteriaBuilder builder, Root&lt;?&gt; root) {
      if (atLeastAverageValue!=null) {
              Expression averageTotalValueExpression = builder.quot(root.get("orderCount"), root.get("orderTotalValue")).as(BigDecimal.class);
              predicates.add(builder.lessThanOrEqualTo(averageTotalValueExpression, atLeastAverageValue));
  
      }
  }
  </code></pre>
  
  <p>Can anyone help?</p>