Querydsl

Querydsl - Typesafe queries for Java

Easy and safe to use, the right tool for agile domain development.

Description

Querydsl (spell: query diesel) is a framework which enables the construction of statically typed SQL-like queries. Instead of writing queries as inline strings or externalizing them into XML files they can be constructed via a fluentDSL/API like Querydsl.

The benefits of using a fluent API in comparison to simple strings are

  • code completion in IDE
  • almost none syntactically invalid queries allowed
  • domain types and properties can be referenced safely
  • adopts better to refactoring changes in domain types

Bookmark with: del.icio.us   digg   Mister Wong   YahooMyWeb   Reddit   Furl   Spurl   blogmarks

Get started

See our module specific integration guides

and for more documentation see Documentation

Supported backends

  • JPAQL/HQL via the querydsl-hql module
  • JDOQL via the querydsl-jdoql module (experimental)
  • RDF via RDFBean, our Object/RDF persistence framework
  • Java Collections via the querydsl-collections module (experimental)
  • SQL/JDBC via the querydsl-sql module (experimental)

In a nutshell

Name Querydsl
Most Recent Version 0.4.6
Javadocs v 0.4.6
State Stable
License LGPL v2.1
Version Control on Mysema Source
Maven repo on Mysema Source
Issue Management on Launchpad
Commercial Support contact us

Popular pages (last 7 days):

Querydsl 126
JDOQL Guide 35
Similar frameworks 21
HQL and JPAQL Guide 17
Collections Guide 13
Documentation 10
Querydsl expressions 9
Querydsl Collections - Performance 5
Developer's Guide 5
SQL Guide 4
Alias usage 4
Querydsl - new frontpage 3
Getting started 2
TreeNavigation 2
Features 1

Examples

The syntax of Querydsl is similar to SQL, but the order of elements is different. Instead of the basic SELECT FROM WHERE pattern, FROM WHERE LIST is used.

Example 1

Get the cats where the name's first character is between A and B :

HQLQuery q = new HQLQueryImpl(session);
QCat cat = new QCat("cat"); // query type
List<Cat> cats = q.from(cat).where(cat.name.between("A", "B")).list(cat);

The related HQL query would be

select cat from Cat cat where cat.name between A and B

As you can see the Querydsl syntax resembles the underlying HQL query very much.

Example 2

Get the cats with kittens :

HQLQuery q = new HQLQueryImpl(session);
QCat cat = new QCat("cat");  // query type
List<Cat> cats = q.from(cat).where(cat.kittens.size().gt(0)).list(cat);

Example 3

Get the mother, mate and offspring and list them as Family instances :

HQLQuery q = new HQLQueryImpl(session);
QCat mother= new QCat("mother"); // query type
QCat mate= new QCat("mate");
QCat offspr= new QCat("offspr");
List<Family> families = q.from(mother).innerJoin(mother.mate, mate).leftJoin(mother.kittens, offspr)
  .list(new QFamily(mother, mate, offspr));

Alternatively you may also write this shorter as

HQLQuery q = new HQLQueryImpl(session);
QCat mother= new QCat("mother"); // query type
QCat offspr= new QCat("offspr");
List<Family> families = q.from(mother).leftJoin(mother.kittens, offspr)
  .list(new QFamily(mother, mother.mate;, offspr));

Labels

querydsl querydsl Delete
frontpage frontpage Delete
dsl dsl Delete
jpa jpa Delete
collections collections Delete
hql hql Delete
jpaql jpaql Delete
sql sql Delete
java java Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.