Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QueryDsl how to use exist() to return boolean

Tags:

java

querydsl

I want to upgrade queryDsl from verision 3 to version 4. But i've an issue with exist() In QueryDsl 3 exist return a Boolean but in QUeryDSL 4 it return a BooleanOperation. In my case i really want the boolean but i don't know how to retrieve it.

The best solution i've found is to do

.fetchCount() >0 

But I want to know if another (better) solution exist.

like image 821
Ruokki Avatar asked Oct 30 '25 22:10

Ruokki


1 Answers

Another option would be something like:

queryFactory.select(queryField).from(qTable)
            .where(queryField.eq(value))
            .groupBy(queryField)
            .having(qTable.uuid.count().gt(0))
            .fetchOne() != null;

This passes the greater than responsibility over to the query. However it is possibly less readible so will depend on the requirements which is better.

like image 181
Alastair Watts Avatar answered Nov 02 '25 13:11

Alastair Watts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!