Querying a database is essential to retrieve information that meets certain criteria. This chapter focuses on Querydsl, one of the alternatives for querying a database from Java programs. The “dsl” part of the Querydsl name refers to domain specific languages (DSLs), which are languages dedicated to particular application domains. For example, querying a database is such a domain.
In this chapter we’ll examine the most important capabilities of Querydsl, and we’ll apply them in a Java persistence project. For comprehensive documentation of Querydsl, see its website: http://querydsl.com/.
There are various alternatives for querying a database from within Java programs. You can use SQL, as has been possible since the early days of JDBC. The drawbacks of this approach are the lack of portability (the queries are dependent on the database and the particular SQL dialect) and the lack of type safety and static query verification.