Querydsl - Unified Queries for Java

Unified Queries for Java.
Querydsl is compact, safe
and easy to learn.

Modules

JPA

The popular choice for SQL persistence with a focus on CRUD and simple queries for object loading. more...

SQL

The alternative SQL abstraction with a focus on SQL operations and the full expressivity of the SQL standard. more...

Mongodb

ODM support via Morphia or Spring Data for MongoDB, the NoSQL of choice for many. more...

JDO

JDO support for Object, SQL and NoSQL storage abstraction. more...

Lucene

Full text indexing via Lucene, the most popular fulltext index for Java. more...

Collections

Java Collection querying for Java Beans and POJOs. more...

Documentation

Examples

Basic query

List<Person> persons = queryFactory.selectFrom(person)
  .where(
    person.firstName.eq("John"),
    person.lastName.eq("Doe"))
  .fetch();
          

Order

List<Person> persons = queryFactory.selectFrom(person)
  .orderBy(person.lastName.asc(), 
           person.firstName.desc())
  .fetch();
          

Subqueries

List<Person> persons = queryFactory.selectFrom(person)
  .where(person.children.size().eq(
    JPAExpressions.select(parent.children.size().max())
                  .from(parent)))
  .fetch();
          

Tuple projection

List<Tuple> tuples = queryFactory.select(
    person.lastName, person.firstName, person.yearOfBirth)
  .from(person)
  .fetch();