title: Criteria API: Select Expression IF [NOT] NULL <value>
body: <p>I'm trying to translate the following simple query into JPA criteria API:</p>
  
  <pre><code>SELECT ticket_action.ticket_id IS NOT NULL, ticket.id
  FROM ticket
  LEFT OUTER JOIN ticket_action ON ticket.id = ticket_action.ticket_id
  </code></pre>
  
  <p>I've tried two approaches:</p>
  
  <ol>
  <li>Using <code>criteriaBuilder.function("ISNULL", Boolean.class, ticketAction.get(TicketAction_.ticketId))</code>: the problem is there is no negation if <code>ISNULL</code> like <code>ISNOTNULL</code> (for a MySQL/MariaDB database)</li>
  <li>Using <code>criteriaBuilder.isNotNull(ticketAction.get(TicketAction_.ticketId))</code>: but this return a <code>Predicate</code> whereas the select statement accepts only <code>Expression</code>s</li>
  </ol>
  
  <p>Stretch goal: The same with <code>GROUP BY ticket.ticket_id IS NOT NULL</code></p>
  
  <hr>
  
  <h2>The table structure as requested</h2>
  
  <pre><code>+-----------+---------+
  |         ticket      |
  +-----------+---------+
  |   name    |  type   |
  +-----------+---------+
  | id        | integer |
  | title     | varchar |
  +-----------+---------+
  
  +-----------+---------+
  |    ticket_action    |
  +-----------+---------+
  |   name    |  type   |
  +-----------+---------+
  | id        | integer |
  | ticket_id | integer |
  | title     | varchar |
  +-----------+---------+
  </code></pre>
  
  <h1>Result:</h1>
  
  <p>Finally I ended up using a construtor query which receives the <code>id</code> of <code>ticket_action</code> among others. In the constructor there is the decision about the state: <code>this.hasTicketAction = ticketActionId != null;</code>
  Not very satisfying, but working.</p>
  
  <p><strong>Thank you though anybody for posting your answers!</strong></p>