I'm currently doing like this.
final CriteriaBuilder builder = ...;
final boolean flag = ...;
if (flag) {
builder.isTrue(expression);
} else {
builder.isFalse(expression);
}
Can I use it like this?
builder.equals(expression, flag);
Is this try won't have any problem? Say null for expression or something.
I suppose you implied using CriteriaBuilder
's equal
method. In this case yes, you can use it as follows:
builder.equal(expression, flag);
And this is equivalent to:
if (flag) {
builder.isTrue(expression);
} else {
builder.isFalse(expression);
}
But be aware that if you use Hibernate
as JPA
provider the former implementation will throw NPE in case expression==null
is true while the latter one won't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With