Api criteria, where 1 <> 1

I want the query to not return any values. I can't just not query the database, so I would like to add some unreachable conditions for predicates, something like "where 1 <> 1". But CriteriaBuilder.equal () does not allow this. Is there a way to achieve the goal?

Thank.

+5
source share
3 answers

What about

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

, , , , . , JPA- 1 <> 1 SQL, ...

+7

Javadoc CriteriaBuilder: " ( ). ".

CriteriaBuilder cb..
Predicate itsFalse = cb.disjunction();

SQL , Hibernate 0 = 1. :

  • , .
  • .
+6

:

CriteriaBuilder.isTrue(CriteriaBuilder.literal(Boolean.FALSE));
+3

All Articles