title: Combined criteria builder function using jsonb_extract_path_text and jsonb_array_elements to extract jsob data from array
body: <p>I am having the problem to extract data using criteria builder function when jsonb column data has array not object. I am looking how to generate this query using builder function in java,</p>
  <p>I need to generate</p>
  <pre><code>select
      arr.position,
      arr.item_object
  from
      events, jsonb_array_elements(data) with ordinality arr(item_object, position)
  where
      jsonb_extract_path_text(arr.item_object,'tenant_id') like '%test%'
  </code></pre>
  <p>my table</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>data</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>[{&quot;events&quot;: [{&quot;date_time&quot;: &quot;2022-04-07T06:35:28.843+00:00&quot;], &quot;tenant_id&quot;: &quot;test&quot;}]</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I could generate</p>
  <pre><code>   select
      event0_.id as id1_2_,
      event0_.data as data6_2_
  from
      events event0_ 
  where
      jsonb_extract_path_text(event0_.data,'tenant_id') like '%test%'
  </code></pre>
  <p>with following code</p>
  <pre><code> Expression&lt;String&gt; function = builder.function(&quot;jsonb_extract_path_text&quot;,
              String.class,
              root.&lt;String&gt;get(&quot;data&quot;),
              builder.literal(&quot;tenant_id&quot;)
      );
      Predicate p = builder.like(
              function,
              &quot;%test%&quot;
      );
      query.where(p);
      Optional&lt;List&lt;Event&gt;&gt; events = Optional.ofNullable(entityManager.createQuery(query.select(root)).getResultList());
  </code></pre>
  <p>Please help me to identify the code that need to be changed to get the results. Thank you in advance!!!</p>