Querydsl 3.0 in a nutshell

Last week we released Querydsl 3.0. The goal of this release was to streamline Querydsl usage. In this post I will highlight a few of the general changes and some JPA/SQL specific ones.

Naming changes

Naming of query and subquery classes has been unified into the following form Query classes:
Module before after
Collections ColQuery (interface) - ColQueryImpl CollQuery
JDO JDOQLQuery (interface) - JDOQLQueryImpl JDOQLQuery (interface) - JDOQuery
SQL SQLQuery (interface) - SQLQueryImpl SQLQuery

No changes in JPA, Mongodb, Lucene and Hibernate Search.

Subquery classes:
Module before after
JPA JPQLSubQuery - JPASubQuery - HibernateSubQuery JPQLSubQuery (interface) - JPASubQuery - HibernateSubQuery
SQL SQLSubQuery SQLSubQuery


Tuples as first-class citizens

We encountered the following pattern often in our code
query.list(new QTuple(...))
and decided to change the varargs list method to return a list of tuples instead of object arrays. Thus
List<Tuple> result = query.list(new QTuple(a, b, …)) 
calls can be refactored into
List<Tuple> result = query.list(a, b, …)
The same change has been performed for the other varargs projection methods of the Projectable interface.


Unified distinct usage

The following distinct usage has been deprecated
query.listDistinct(a, b, c)
The preferred usage is now
query.distinct().list(a, b, c)
Which is more in line with other modifiers that are applied to the query.


Deeper defaults for path initialization

Querydsl metaclasses are now initialized one level further, so now there are less risks of running into issues when deep paths are used. And if you want to be absolute sure that all paths are initialized you can always use the accessor option as documented here.


Improved iteration for JPA

The iterate methods in Querydsl JPA query classes have been optimized to utilize Hibernate and EclipseLink specific iteration support. For Hibernate ScrollableResults are used and for EclipseLink Cursors.


Batoo JPA support

Batoo JPA is now officially supported by Querydsl.


Roo support

The @RooJpaEntity annotation of the Spring Roo project is now officially supported via the com.mysema.query.apt.roo.RooAnnotationProcessor processor. The workaround of using GenericExporter is no longer necessary.


with -> on

The with method for Querydsl JPA queries has been replaced with on, to promote a more consistent line of keywords in the query interfaces.


Support for order by nulls first

Explicit null ordering is now supported in Querydsl SQL. The supported extensions are


Builder methods for SQLTemplates types

The previous method of customizing SQLTemplates subclasses was a little awkward and involved further subclassing like this
new H2Templates(true){{
Querydsl 3 promotes now the usage of builder classes for customization



The full list of changes for the 3.0 release are in 3.0.0, 3.0.0.BETA2 and 3.0.0.BETA1.

The latest stable release of Querydsl is 3.1. It fixes some packaging issues of the 3.0 release: https://groups.google.com/forum/#!topic/querydsl/I562uKQlheE. Usage of the 3.1 release is recommended.

Happy querying!

No comments:

Post a Comment