JPQL limit 1 row result

1
0
-1

Is-it possible in JPQL query to limit result to 1 row ? like TOP 1 or LIMIT 1 in SQL.
Or i'm obliged to use a Multiple type result (Java.util.List) and control the number of rows in my groovy script ?

Thanks

1 answer

1
0
-1
This one is the BEST answer!

In the JPQL query it self it is not possible (like in SQL) to limit the number of results.

Such limit can actually be enforced when executing the JPQL query but Bonita does not do that.

What you can do is to define a JPQL that you know (it is up to you to enforce that) will only return a single result (e.g. filtering on primary key) and choose the "Result type" "Single" in the Studio window that let you create your JPQL query.

Alternatively you can:

  • Programmatically run your query in order to limit it to a single result. In a Groovy script: testBusinessClassDAO.testQuery(0, 1).first() // 0 is to get the first page of result, 1 is to limit the result to only 1, first() function is used as running the query will return a list with a single entry and first will return this single object.
  • In a REST API call: http://localhost:8080/bonita/API/bdm/businessData/com.company.model.Test...
Notifications