Home » Support » Forum » Help with JPA2 Criteria and conditional operator grouping

Help with JPA2 Criteria and conditional operator grouping



  I'm getting a little trouble performing a query as per the way I had it set up on eclipselink. Essentially, the query I'm trying to generate is:

(($1.companyId=:p1) AND ($1.conditionOne=true)) AND
(($1.conditionTwo=false) OR ($1.conditionThree=false))


From the JPA2 criteria:

CriteriaBuilder builder = em.getCriteriaBuilder();
  CriteriaQuery<Company> c = builder.createQuery(Company.class);
  Root<Company> root = c.from(Company.class);
  ParameterExpression<String> nameParam = builder.parameter(String.class);
  Path<String> namePath = root.get("companyId");
  Path<Boolean> conditionOnePath = root.get("conditionOne");
  Path<Boolean> conditionTwoPath = root.get("conditionTwo");
  Path<Boolean> conditionThreePath = root.get("conditionThree");
    builder.and(builder.equal(namePath, nameParam),
               builder.equal(conditionOnePath, true)),
            builder.equal(conditionTwoPath, false),
            builder.equal(conditionThreePath, false)
  System.out.println("Query: " + c);

But I can can never get the grouping to occur around the 'or'. Hence, my logic conditions is failing. The same EJB running against my eclipselink persistence.xml shows the grouping happening. I've had to dumb down the domain model enough to convey the issue I'm getting, so the actual query will probably not make much sense. The generated objectdb query looks like this:

SELECT $1 FROM Company $1 WHERE ($1.companyId=:p1) AND ($1.conditionOne=true) AND ($1.conditionTwo=false) OR ($1.conditionThree=false)

Even though the the JPA2 criteria 'wraps' the conditionals around an AND/OR block, all the conditionals are being generated individually. Is this correct or have I missed something again?


Attached is the test case I'm using to generate this.




ObjectDB Version: 2.2.8_02




This is a bug. Thank you for the report and for the test case.

Please try build 2.2.8_04 that should fix the bug.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

That fixed the conditional grouping issue. Thanks.


There is a new problem now however, I'll create a new post

Post Reply

To post a reply and/or subscribe to update notifications - please login