19 Querying JPA with Querydsl
This chapter covers
- Introducing Querydsl
- Creating a Querydsl application
- Querying a database with Querydsl
Querying a database is essential to retrieve information that meets certain criteria. A Domain Specific Language (DSL) is a language dedicated to a particular application domain. For example, querying a database is an example of such a particular domain. This chapter focuses on Querydsl, one of the alternatives to query a database using Java programs. We’ll examine its most important capabilities and will apply them in a Java persistence project. For comprehensive documentation of Querydsl, you may access http://querydsl.com/.
19.1 Introducing Querydsl
There are various alternatives to query a database from within Java programs. You may use SQL, as it was possible since the early days of JDBC. The drawbacks of using this approach were 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.
JPQL (Jakarta Persistence Query Language) was a step forward, being an object-oriented query language that is independent of the database. This means no more lack of portability but still a lack of type safety and static query verification.