Typed queries and fetch plans
Latest stable Based on Bluetape4k release 1.11.0
Reified APIs
Section titled “Reified APIs”findAs<T>, createQueryAs<R>, createSelectionQueryAs<R>, createNamedQueryAs<R>, and createNativeQueryAs<R> remove repeated T::class.java arguments. Hibernate still validates the query text and result mapping.
val books = sessionFactory.withSessionSuspending { session -> session.createSelectionQueryAs<Book>( "select b from Book b left join fetch b.author" ).resultList.awaitSuspending()}The tests show findAs returning null for an unknown ID. getReferenceAs may return a proxy immediately, and reading its ID does not imply a database lookup. Initializing other properties still requires a live session and row.
Mutiny and Stage differences
Section titled “Mutiny and Stage differences”Do not assume that the two packages are identical from their common function names.
- Mutiny Session supports Hibernate
LockMode, JPALockModeType, multiple IDs, natural IDs, EntityGraphs, and graph-name lookup. - Stage Session supports Hibernate
LockMode, multiple IDs, and natural IDs, but has noLockModeTypeor EntityGraphfindAsoverload. - Mutiny StatelessSession likewise has more
getAsoverloads than Stage.
Fetching lazy associations
Section titled “Fetching lazy associations”Book.author and Author.books in the tests are lazy associations. Resolve required relationships inside the session using one of these approaches:
- an HQL fetch join;
- an enabled
@FetchProfile; createEntityGraphAsor the namedBook.withAuthorgraph;- explicit Hibernate Reactive
fetch().
The Criteria examples use generated JPA metamodel types Author_ and Book_, not Querydsl. The module build deliberately selects the metamodel generator.
Native query and mapping
Section titled “Native query and mapping”The type argument to createNativeQueryAs<R> does not guarantee that arbitrary SQL results match R. State whether the result is a scalar, entity, or registered result-set mapping and verify it against the actual database. The AffectedEntities overload supplies synchronization hints for native queries and the persistence context.