Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring JPA: Query builder versus Criteria Builder , which one to use?

I am going to start new project that would play with very large database, thus would be having lots of database operation.

I have decided to use Spring JPA as my ORM. Now Spring JPA provides various techniques to use in DAO layer. I am confused between Criteria builder and Query DSL. Both seems to solve my problem well and I guess there is not point using both of them in a same project because they provide same functionality.

So now which one to use and why ?

like image 396
Dhruv Bansal Avatar asked Apr 28 '13 10:04

Dhruv Bansal


1 Answers

The JPA 2 Criteria API and Querydsl are equivalent in functionality, but Querydsl has been designed to be more fluent and look more like JPQL/SQL. So it can be used as a replacement for both JPQL and JPA 2 Criteria.

Here is also a blogpost on the topic which shows how compact Querydsl queries are in comparison to the JPA 2 Criteria API Querydsl as an alternative to the JPA 2 Criteria API

This answer is biased, since I am behind Querydsl.

like image 115
Timo Westkämper Avatar answered Sep 25 '22 14:09

Timo Westkämper