liveBook · Manning

Q-type

As explained in Java Persistence with Spring Data and Hibernate epub

A Q-type is a generated Querydsl metamodel class that represents an entity and exposes typed representations of its queryable properties.

A Q-type is a generated Querydsl metamodel class corresponding to a JPA entity. Annotation processing creates one class per entity during the Maven build, and mirrors queryable fields with typed Querydsl paths such as StringPath and NumberPath<Long>. section 19.2.1

The generated classes are placed under target/generated-sources/java and expose static instances used as query roots. JPAQueryFactory creates JPAQuery objects that use these roots to build database queries. section 19.3 section 19.3.1

Filtering with a Q-type

QUser.user identifies the User entity, while username provides a typed predicate. The query returns one matching entity, returns null when none matches, and throws NonUniqueResultException when several match. section 19.3.1

public static final QUser user = new QUser("user");
public static final QBid bid = new QBid("bid");
public static final QAddress address = new QAddress("address");

Generated static query roots for User, Bid, and Address. section 19.3.1

Configure querydsl-jpa, querydsl-apt, and the Maven APT plugin to generate Q-types. Use the JPA annotation processor for JPA entities; the annotation-processing dependency is needed at build time rather than in application artifacts. section 19.2.1

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains build-time generation, typed property paths, static instances, and query usage, but defers generated-class internals.
Examples
Uses QUser.user to find a username and combine level and active predicates.
What it assumes
Assumes JPA entities and Maven configuration, while teaching Q-type generation and typed query-property mapping.
What you can do after
Apply it via Querydsl to build type-safe filters, ordering, grouping, joins, updates, and deletes.
How it connects
Connects JPA entities, annotation processing, Maven, Querydsl, JPAQueryFactory, JPAQuery, predicates, and database queries.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.