我在使用
javax.persistence.criteria.CriteriaBuilder创建查询时遇到问题.我正在使用
EclipseLink 2.1和Oracle 10g数据库.在构建具有多个限制的查询时,它将仅使用第一个限制,而不是两个限制.
这是我的代码:
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaQuery<Assignment> query = cb.createQuery(Assignment.class); Root<Assignment> assignment = query.from(Assignment.class); query.where( cb.equal(assignment.get("request"),request),cb.isNull(assignment.get("endDate"))); return getEm().createQuery(query).getResultList();
SELECT ASSX_ID,END_DATE,BEGIN_DATE,COMMENTS,ASSX_OER_ASSIGNED_TO_ID,OER_OER_ID_ASSIGNED_BY,ASSX_RQST_ID FROM TARTS.ASSIGNMENT_XREF WHERE (ASSX_RQST_ID = ?)
除了where子句外,它看起来不错.我期待:
SELECT ASSX_ID,ASSX_RQST_ID FROM TARTS.ASSIGNMENT_XREF WHERE (ASSX_RQST_ID = ? AND BEGIN_DATE IS NOT NULL)
如果我使用cb.and(arg1,arg2)也没关系.难道我做错了什么?任何帮助将不胜感激.