Criteria – multiple expressions in the JPA querybuilder where clause do not work

I'm using javax persistence. criteria. Criteriabuilder encountered a problem creating the query I am using eclipse link 2.1 and Oracle 10g database When building a query with multiple constraints, it will only use the first constraint, not the two constraints

This is my code:

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();

The generated query is:

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 = ?)

It looks good except for the where clause I look forward to:

SELECT ASSX_ID,ASSX_RQST_ID FROM TARTS.ASSIGNMENT_XREF 
WHERE (ASSX_RQST_ID = ? AND BEGIN_DATE IS NOT NULL)

If I use CB And (arg1, arg2) doesn't matter Did I do something wrong? Any help would be appreciated

Solution

Your query looks very good As you mentioned, criteriaquery Where (predicate... Restriction) already uses the combination of predicates, so CB is not required and().

The only thing I can think of:

>Error in eclipse link (like hibernate) > some kind of optimization, maybe enddate may never be empty? > Your getem () method does something strange

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>