Java criteria builder query not null or empty
<p>I'm trying to check if a column in the db is not an empty string or not null but I can't figure out how to do it with criteria builder queries in order to get actual objects back.  This sql works: </p>

<pre><code>sampleName is not null and sampleName != ''
</code></pre>

<p>But when I try to do it with criteria builder like this:</p>

<p>// this is in a private method filterBySampleNotEmpty</p>

<pre><code>cb.notEqual(root.get("sampleName"), "");
</code></pre>

<p>called by this in another method</p>

<pre><code>CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery&lt;Sample&gt; query = criteriaBuilder.createQuery(Sample.class);
Root model = query.from(Sample.class);
List&lt;Predicate&gt; predicates = new ArrayList&lt;&gt;();
predicates.add(filterBySampleNotEmpty(model, criteriaBuilder));
query.select(model).where(predicates.toArray(new Predicate[]{}));
</code></pre>

<p>It returns the whole list still.  </p>