Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why to use Querydsl? [closed]

Tags:

jpa

jpql

querydsl

I am new to JPA, JPQL, Hibernate, Querydsl and now I saw that in my project is used Querydsl for querying and I am wondering why this approach has been chosen. So you can be for sure why exactly is in my project but you can tell why and in what situations Querydsl is preferred. Why we can use simple JPQL statements?

like image 231
Xelian Avatar asked Jan 13 '15 10:01

Xelian


Video Answer


2 Answers

  • You can use code completion in IDE
  • IDE refactoring tools work (more-or-less)
  • type-safe
  • (almost)syntax-safe
  • compiler generates errors on compile time of wrong types etc vs Hibernate complains just on first run
  • Consistency, you can use same principles to query JPA, MongoDB, Collections...
like image 75
ikettu Avatar answered Oct 21 '22 07:10

ikettu


I would like to make a counterpoint to the QueryDSL usage.

I don't like to use QueryDSL for the follow reasons:

  • You need to compile the project frequently to maintain the Q classes updated
  • You need to setup the IDE to consider the Q classes generated on target as normal classes.
  • I have already seen the IDE "get lost" and no longer recognize the Q classes
  • I already create simple QueryDSL statements that generated really weird and not predictable SQLs.

Even being friendly for final users, I prefer to use JPQL because it's more closer to the generated SQL and more predictable.

But compared to Criteria, I prefer QueryDSL.

like image 44
Dherik Avatar answered Oct 21 '22 08:10

Dherik