In addition, you can also create your own custom DSL
Execute the query
After building the query, you can use RenderContext to execute the query. For example, you can use JpqlRenderContext to execute the query:
RenderContext has elements for rendering the query as String. Kotlin JDSL provides JpqlRenderContext as the default RenderContext for the JPQL.
JpqlRenderer renders the query as String using the RenderContext. This returns JpqlRendered, which has the query rendered as String and the parameters contained in the query. This has no state, so you can reuse the object of this and access it from multiple threads.
Creating RenderContext is expensive, so the Kotlin JDSL recommends creating it once and reusing it afterward. Since RenderContext is immutable, you can access RenderContext from multiple threads.
Kotlin JDSL Support provides extension functions for EntityManager to simplify the above process. Using them, you can execute queries as simple as: