I have some experience with Criteria API but I have never used QueryDsl before. What I want to ask is what are the advantages/disadvantages of using QueryDsl instead of Criteria API? Especially I want to learn which one is more suitable for huge databases(I mean complex queries).
Asked
Active
Viewed 5,917 times
2 Answers
11
Querydsl is
- more compact
- more typesafe (at least compared to Hibernate Criteria)
- closer to JPQL syntax
- also available for other backends
This answer is biased since I am a Querydsl contributor.

Timo Westkämper
- 21,824
- 5
- 78
- 111
-
Could you explain how is it more type safe? With TypedQuery(https://docs.oracle.com/javaee/6/api/javax/persistence/TypedQuery.html) we can get typesafety even with Criteria API. isn't it so? – pvpkiran Nov 15 '18 at 14:43
-
Currently QueryDSL is stuck with hibernate versions < 5.2, and no commits since 8 months ago: https://java.libhunt.com/compare-jooq-vs-querydsl – cdalxndr Nov 27 '18 at 16:46
-
@timo What about performance? Hibernate provides default caching for a session. And I found, queries which needed pagination, performs better (as it seems DSL making extra queries which I do not need) in case of Hibernate criteria (on same DB config). Am I doing something wrong? – Vivek Vardhan Oct 25 '19 at 07:13
2
QueryDSL is a level of abstraction above criteria; Also, it is more similar to SQL so it might be easier to learn for people who have not touched Criteria before.

M Rajoy
- 4,028
- 14
- 54
- 111