Friday, January 7, 2011

Smooth queries with QueryDSL

Have you ever used Hibernate's criteria API and thought it could be more intuitive?

Do you think that JPA2's criteria typesafe queries are hard to read?

Then I recommend that you take a look at the following project

Compare this code: with this one:

Now it's typesafe and MUCH smoother and intuitive.

Check the following page for more examples of QueryDSL vs JPA2 Criteria

QueryDSL makes it easy (at last) to work with criteria queries. Did I mention that it can also be used with JDO, Lucene, JDBC and even plain collections?

For example if you are already using QueryDSL to replace the plain criteria API then you are all set to query any collections containing your domain objects anywhere in your code :). All you need to do is import the collections API.

This code would then replace your typical loop.

Congratulations to Timo Westkämper and to the QueryDSL team!


  1. Thanks for the promotion. I'd like to add that Querydsl is a team effort. Querydsl wouldn't be where it is without the ideas and code of my colleagues and all the user feedback we get.

    Happy querying! ;)

  2. Hi I am using QueryDsl with Hibernate and trying to Eager Load the child entities but couldn't get them as joined queries. Fetchmode Join seems not working with it. Any help would be really appericiated.