Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

criteria api where 1<>1 clause

I want the query not to return any values. I can't just not query database, so I'd like to add some unreachable condition to predicates, something like 'where 1 <> 1'. But the CriteriaBuilder.equal() doesn't allow to do that. Is there any way to reach the goal?

Thanks.

like image 491
Vladimir Ivanov Avatar asked Aug 08 '11 10:08

Vladimir Ivanov


1 Answers

How about

CriteriaBuilder.notEqual(CriteriaBuilder.literal(1), 1)

Although, if you know that this shouldn't execute, then using expressions might not be optimal on some RDBMS, if the database can't peek at bind values. I don't know how to do create a JPA Predicate with an inlined 1 <> 1 SQL expression, though...

like image 194
Lukas Eder Avatar answered Sep 23 '22 15:09

Lukas Eder