admin管理员组文章数量:1123260
We are using jakarta.jakartaee-api as a dependency in our project, so that we can use the CriteriaBuilder/CriteriaQuery features. An array of Predicates is used to create multiple conditions. One of the Predicates is a used to build an "IN" clause.
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>11.0.0-M4</version>
<scope>provided</scope>
</dependency>
...
predicates = new Predicate[] {
...
criteriaBuilder.in(root.get("zone").in(zoneList))
...
}
criteriaQuery.where(predicates);
The list "zoneList" contains two elements.
The generated SQL part for the "IN" clause contains IN (NULL)
, and therefore no rows are found in the DB.
AND (
(
t0.zone IN (?, ?)
) IN (NULL)
)
Why is Jakarta adding IN (NULL)
in the generated SQL?
Here's the complete Java Code
public List<DBEntity> report() { EntityManager em = getEntityManager(); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<DBEntity> criteriaQuery = cb.createQuery(DBEntity.class); Root<DBEntity> root = criteriaQuery.from(DBEntity.class); Predicate[] predicates = new Predicate[] { cb.in(root.get("zone").in(Arrays.asList("Zone 1"))) }; criteriaQuery.where(predicates); criteriaQuery.select(root); TypedQuery<DBEntity> query = em.createQuery(criteriaQuery); return query.getResultList(); }
本文标签:
版权声明:本文标题:java - Why is jakarta.jakartaee-api adding "IN (NULL)" in the generated SQL for a Predicate 'in clause 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736560929a1944644.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论