title: How to select entities until sum reaches to certain values in jpql?
body: <p>I found one solution for this question in mysql but it doesn't work with jpa.</p>
  <pre class="lang-sql prettyprint-override"><code>select t.* 
  from (select t.*, 
      (@sum := @sum + quantity) as cume_stock 
      from exchange_service.order_book t 
      cross join (select @sum := 0) params order by id 
  ) t 
  where cume_stock &lt; 10000 
  or (cume_stock &gt;= 100 and cume_stock - quantity &lt; 10000);
  </code></pre>