JEHibernate gives you two ways to query beyond id lookups: a fluent query builder for one-off queries, and Specifications for reusable, composable predicates. Both avoid hand-written JPQL for the common cases.
The query builder
repo.query() returns a QueryBuilder you chain and terminate.
Available filters: and, or, notEqual, like, orLike, in, between, isNull, isNotNull, , , , . Chained filters combine with AND; / start an OR branch.
greaterThan
lessThan
greaterThanOrEqual
lessThanOrEqual
or(...)
orWhere(...)
Terminals:
Every terminal has an async form (listAsync, firstAsync, countAsync, getPageAsync).
Sorting, paging, and fetch joins
fetch(assoc) is an inner join fetch; fetchLeft(assoc) is a left join fetch.
Specifications
A Specification is a reusable predicate you can name, store, and combine. Build them with the Specifications factory and pass them to the spec-aware repository methods.
Factory methods: equalTo, notEqualTo, like, in, isNull, isNotNull, greaterThan, lessThan, greaterThanOrEqual, lessThanOrEqual, between. Because specifications are plain objects, you can keep a library of them next to your domain and reuse them across repositories and services.
Specifications compose with and, or, and not, so you keep named predicates and combine them per call site — and it all runs in SQL:
Fetching associations without N+1
Loading a list and then touching a lazy association per row triggers the classic N+1 problem. EntityGraph helpers fetch the associations in the same query.
When to reach for what
Use the query builder for ad-hoc queries, Specifications for predicates you reuse, and EntityGraph helpers whenever a list view reads a lazy association. Keep associations LAZY by default and fetch explicitly where you need them.
List<Warp> all = repo.query().like("name", "a%").list();
Optional<Warp> one = repo.query().and("name", "spawn").first();
long matches = repo.query().greaterThan("uses", 5).count();
boolean any = repo.query().and("world", "nether").exists();
PageResult<Warp> pg = repo.query().orderBy("name").getPage(0, 20); // rows + total
Stream<Warp> stream = repo.query().stream(); // streamed results
List<Warp> page = repo.query()
.and("world", "world")
.orderByDesc("createdAt")
.fetchLeft("owner") // LEFT JOIN FETCH — avoids a second query for owner
.page(1, 25)
.list();
import static de.jexcellence.jehibernate.repository.query.Specifications.*;
Specification<Warp> popular = greaterThan("uses", 100);
Specification<Warp> inNether = equalTo("world", "nether");
List<Warp> found = repo.findAll(popular);
Optional<Warp> one = repo.findOne(inNether);
long count = repo.count(popular);
boolean exists = repo.existsBy(inNether);
// fetch the "members" and "owner.profile" associations in one query
List<Guild> guilds = guildRepo.findAllWithGraph("members", "owner.profile");
Optional<Guild> g = guildRepo.findByIdWithGraph(id, "members");
// or a named @NamedEntityGraph declared on the entity
Optional<Guild> g2 = guildRepo.findByIdWithNamedGraph(id, "Guild.withMembers");