Hi,
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:
SELECT $1 FROM Company $1 WHERE (($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"); c.select(root); c.where( builder.and(builder.equal(namePath, nameParam), builder.equal(conditionOnePath, true)), builder.and( builder.or( 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.
Thanks
ObjectDB Version: 2.2.8_02