Hi All,
I'm creating query with JPA Criteria API:
Code:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery();
Root cr = cq.from(City.class);
cq.select(cr);
Predicate p = cb.or(cb.like(cr.get("cityInfo"), "%1%"), cb.isNull(cr.get("cityInfo")));
p = p.not(); // THIS LINE has no effect
cq.where(p);
Query q= em.createQuery(cq);
List<City> cities = q.getResultList();
Generated query is (does not matter with or without negation):
Code:
select
city0_.cityId as cityId0_,
city0_.cityInfo as cityInfo0_,
city0_.cityName as cityName0_,
city0_.countryId as countryId0_
from
City city0_
where
city0_.cityInfo like ?
or city0_.cityInfo is null
I've found out that created predicate is instance of org.hibernate.ejb.criteria.predicate.CompoundPredicate.
Method render() takes into account isNegated() only when there is no expressions.
isNegated() is not checked if expressions exist.
I've checked JSR317 and haven't found any exceptions regarding negation and compound predicates.
Should I register bug in JIRA or am I missing something?
Best regards,
Alius.