Skip to content
Bluetape4k docs1.11

JPQL, Criteria, and Querydsl

Latest stable Based on Bluetape4k release 1.11.0

Use findAs for an ID, typed JPQL for a fixed query, and Criteria or Querydsl when conditions must be composed.

val active = entityManager
.createQueryAs<Account>("select a from Account a where a.active = true")
.setPaging(0, 50)
.resultList

findOneOrNull converts only NoResultException to null. Non-unique and database failures still propagate. Natural-ID helpers support one @NaturalId or a non-empty map of composite attributes.

val cb = entityManager.criteriaBuilder
val query = cb.createQueryAs<Account>()
val root = query.from<Account>()
query.select(root).where(cb.eq(root.attribute(Account::active), true))

attribute uses the Kotlin property name as the JPA path. It reduces strings but is not a generated metamodel check.

Querydsl fits joins, subqueries, projections, and reusable predicates. Q types still require annotation processing. Select constructor, bean, or @QueryProjection mapping based on compile-time checks and coupling.

Query shapeStart with
ID or natural IDreified lookup helper
Short fixed querytyped JPQL
JPA-standard dynamic queryCriteria
Kotlin joins and projectionsQuerydsl
Entity Views and keyset pagesBlaze-Persistence demo

Avoid deprecated Querydsl fetchCount() and fetchResults() shortcuts for complex queries; use an explicit count or Blaze-Persistence page metadata.

Terminal window
./gradlew :bluetape4k-hibernate:test --tests '*SimpleQuerydslExamples'
./gradlew :bluetape4k-examples-jpa-querydsl-demo:test
./gradlew :bluetape4k-examples-jpa-blazepersistence-demo:test