openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fay Wang (JIRA)" <>
Subject [jira] Created: (OPENJPA-1814) JPQL fails with Group By and Having aggregate_expression IN (subquery)
Date Fri, 24 Sep 2010 18:16:32 GMT
JPQL fails with Group By and Having aggregate_expression IN (subquery)

                 Key: OPENJPA-1814
             Project: OpenJPA
          Issue Type: Bug
          Components: kernel
    Affects Versions: 2.1.0
            Reporter: Fay Wang
            Assignee: Fay Wang

The following JPQL fail:

    	String jpql = "SELECT a.uuid from EntityA a WHERE = 'test' " + 
    	    "GROUP BY a.date1, a.uuid " +

(1)    "HAVING MAX(a.date1) IN (SELECT MAX(a1.date2) from EntityA a1 WHERE = 'test')
(2)    "HAVING MAX(a.date1) = (SELECT MAX(a1.date2) from EntityA a1 WHERE = 'test')

org.apache.openjpa.persistence.ArgumentException: Encountered "MAX ( a .date1) IN" at character
168, but expected: ["(", ")", "*", "+", "-", ".", "/", ":", "<", "<=", "<>", "=",
">", ">=", "?", "ABS", "ALL", "AND", "ANY", "AS", "ASC", "AVG", "BETWEEN", "BOTH", "BY",
 at org.apache.openjpa.kernel.jpql.JPQL.generateParseException(
 at org.apache.openjpa.kernel.jpql.JPQL.jj_consume_token(
 at org.apache.openjpa.kernel.jpql.JPQL.conditional_primary(
 at org.apache.openjpa.kernel.jpql.JPQL.conditional_factor(
 at org.apache.openjpa.kernel.jpql.JPQL.conditional_term(

The fix involves two changes:
(1) jjt grammar change
(2) OpenJPA performs a preliminary validation to ensure the expression in the having clause
is included in the group-by list. However, this validation checking should be done only on
the LHS of the having clause (see expr1 below), not on the RHS (see expr2 below).  For example:

     Having expr1 = expr2

Only expr1 should be in the group-by list

The current visitor pattern can not tell which node to visit without massive change. The alternative
is to disable the checking by OpenJPA and let the backend to determine whether the generated
SQL is valid or not.


This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message