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!