On 13/08/2008, at 8:17 PM, Andrus Adamchik wrote:
> On Aug 13, 2008, at 11:05 AM, Lachlan Deck wrote:
>
>> I get the following complaining about the asterix '*'. Is that a bug?
>
> No this is not a bug. This is a spec feature. Do "count(a)" instead.
I've tried this also. I've got a class (StatsQuery extends
IndirectQuery) and the method of interest looks like this:
public Number queryResult(ObjectContext oc) {
ObjEntity objEntity = oc.getEntityResolver().getObjEntity(entityName);
if (objEntity == null)
throw new CayenneRuntimeException("No ObjEntity is mapped for java
class: " + this.objClass.getName());
StringBuilder query = new StringBuilder("SELECT
").append(this.statsType).append("(");
if (this.attributeName != null && !"*".equals(this.attributeName))
query.append(this.attributeName);
else
query.append("a");
query.append(") FROM ").append(objEntity.getName()).append(" a");
if (this.expression != null) {
query.append(" WHERE ").append(this.expression.toEJBQL("a"));
}
logger.warn("query --> " + query);
EJBQLQuery ejbqlQuery = new EJBQLQuery(query.toString());
return (Number) DataObjectUtils.objectForQuery(oc, ejbqlQuery);
}
I get the following stack traces (from three different queries)..
1)
query --> SELECT count(a) FROM CourseClass a WHERE (a.isDeleted =
null) or (a.isDeleted = false)
[java]
[java] 14/08/2008 06:35:19
com.caucho.hessian.server.HessianSkeleton invoke
[java] WARNING: org.apache.cayenne.CayenneRuntimeException: [v.
3.0-SNAPSHOT Jul 09 2008 01:28:38] Query exception.
[java] org.apache.cayenne.CayenneRuntimeException: [v.3.0-
SNAPSHOT Jul 09 2008 01:28:38] Query exception.
[java] at
org
.apache
.cayenne
.access
.DataDomainQueryAction.nextQueryException(DataDomainQueryAction.java:
551)
[java] at
org.apache.cayenne.access.DataNode.performQueries(DataNode.java:237)
[java] at
org
.apache
.cayenne
.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:424)
[java] at org.apache.cayenne.access.DataDomainQueryAction.access
$0(DataDomainQueryAction.java:403)
[java] at org.apache.cayenne.access.DataDomainQueryAction
$2.transform(DataDomainQueryAction.java:397)
[java] at
org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:
847)
[java] at
org
.apache
.cayenne
.access
.DataDomainQueryAction
.runQueryInTransaction(DataDomainQueryAction.java:394)
[java] at
org
.apache
.cayenne
.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:120)
[java] at
org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:740)
[java] at
org
.apache
.cayenne
.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:
317)
[java] at
org
.apache
.cayenne
.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
[java] at
org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1336)
[java] at
org.apache.cayenne.access.DataContext.performQuery(DataContext.java:
1325)
[java] at
org.apache.cayenne.DataObjectUtils.objectForQuery(DataObjectUtils.java:
274)
[java] at
ish.persistence.StatsQuery.queryResult(StatsQuery.java:161)
[java] <...>
[java] Caused by: org.apache.cayenne.ejbql.EJBQLException: [v.
3.0-SNAPSHOT Jul 09 2008 01:28:38] Invalid identification variable: null
[java] at
org
.apache
.cayenne
.access
.jdbc
.EJBQLConditionTranslator
.visitIdentificationVariable(EJBQLConditionTranslator.java:486)
[java] at
org
.apache
.cayenne
.ejbql
.parser
.EJBQLIdentificationVariable.visit(EJBQLIdentificationVariable.java:35)
[java] at
org.apache.cayenne.ejbql.parser.SimpleNode.visitChild(SimpleNode.java:
84)
[java] at
org
.apache.cayenne.ejbql.parser.EJBQLEquals.visitChild(EJBQLEquals.java:40)
[java] at
org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
[java] at
org.apache.cayenne.ejbql.parser.SimpleNode.visitChild(SimpleNode.java:
84)
[java] at
org.apache.cayenne.ejbql.parser.EJBQLOr.visitChild(EJBQLOr.java:40)
[java] at
org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
[java] at
org
.apache
.cayenne
.access.jdbc.EJBQLJoinAppender.appendTable(EJBQLJoinAppender.java:193)
[java] at
org
.apache
.cayenne
.access
.jdbc.EJBQLFromTranslator.visitFromItem(EJBQLFromTranslator.java:64)
[java] at
org
.apache
.cayenne.ejbql.parser.EJBQLFromItem.visitNode(EJBQLFromItem.java:89)
[java] at
org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:60)
[java] at
org.apache.cayenne.ejbql.parser.SimpleNode.visitChild(SimpleNode.java:
84)
[java] at
org.apache.cayenne.ejbql.parser.EJBQLFrom.visitChild(EJBQLFrom.java:40)
[java] at
org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
[java] at
org
.apache
.cayenne
.access
.jdbc.EJBQLSelectTranslator.visitFrom(EJBQLSelectTranslator.java:56)
[java] at
org.apache.cayenne.ejbql.parser.EJBQLFrom.visitNode(EJBQLFrom.java:35)
[java] at
org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:60)
[java] at
org.apache.cayenne.ejbql.parser.SimpleNode.visitChild(SimpleNode.java:
84)
[java] at
org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
[java] at org.apache.cayenne.access.jdbc.EJBQLAction
$1.visitSelect(EJBQLAction.java:73)
[java] at
org.apache.cayenne.ejbql.parser.EJBQLSelect.visitNode(EJBQLSelect.java:
35)
[java] at
org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:60)
[java] at
org
.apache.cayenne.access.jdbc.EJBQLAction.performAction(EJBQLAction.java:
67)
[java] at
org
.apache
.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:
58)
[java] at
org.apache.cayenne.access.DataNode.performQueries(DataNode.java:230)
[java] ... 41 more
2)
[java] query --> SELECT count(a) FROM CourseClass a WHERE
((a.isDeleted = null) or (a.isDeleted = false)) and ((a.endDateTime >=
Thu Aug 14 00:00:00 EST 2008) or (a.endDateTime = null)) and
(a.isCancelled != true)
[java]
[java] 14/08/2008 06:35:19
com.caucho.hessian.server.HessianSkeleton invoke
[java] WARNING: org.apache.cayenne.ejbql.EJBQLException: [v.3.0-
SNAPSHOT Jul 09 2008 01:28:38] Error parsing EJB QL statement
[java] org.apache.cayenne.ejbql.EJBQLException: [v.3.0-SNAPSHOT
Jul 09 2008 01:28:38] Error parsing EJB QL statement
[java] at org.apache.cayenne.ejbql.parser.EJBQL
$EJBQLDefaultParser.compile(EJBQL.java:31)
[java] at
org.apache.cayenne.query.EJBQLQuery.getExpression(EJBQLQuery.java:86)
[java] at
org
.apache
.cayenne.query.EJBQLQueryMetadata.resolve(EJBQLQueryMetadata.java:45)
[java] at
org.apache.cayenne.query.EJBQLQuery.getMetaData(EJBQLQuery.java:52)
[java] at
org
.apache
.cayenne
.util.ObjectContextQueryAction.<init>(ObjectContextQueryAction.java:79)
[java] at
org
.apache
.cayenne
.access.DataContextQueryAction.<init>(DataContextQueryAction.java:49)
[java] at
org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1336)
[java] at
org.apache.cayenne.access.DataContext.performQuery(DataContext.java:
1325)
[java] at
org.apache.cayenne.DataObjectUtils.objectForQuery(DataObjectUtils.java:
274)
[java] at
ish.persistence.StatsQuery.queryResult(StatsQuery.java:161)
[java] <...>
[java] Caused by:
org.apache.cayenne.ejbql.parser.ParseException: Encountered "a .
endDateTime >= Thu Aug" at line 1, column 96.
[java] Was expecting one of:
[java] "(" ...
[java] "NOT" ...
[java] "+" ...
[java] "-" ...
[java] <DECIMAL_LITERAL> ...
[java] <INTEGER_LITERAL> ...
[java] ":" ...
[java] "?" ...
[java] "db:" ...
[java] <IDENTIFIER> "." "NEW" ...
[java] <IDENTIFIER> "." "ALL" ...
[java] <IDENTIFIER> "." "ANY" ...
[java] <IDENTIFIER> "." "EXISTS" ...
[java] <IDENTIFIER> "." "SOME" ...
[java] <IDENTIFIER> "." "EMPTY" ...
[java] <IDENTIFIER> "." "ASC" ...
[java] <IDENTIFIER> "." "DESC" ...
[java] <IDENTIFIER> "." "ORDER" ...
[java] <IDENTIFIER> "." "IS" ...
[java] <IDENTIFIER> "." "MEMBER" ...
[java] <IDENTIFIER> "." "OF" ...
[java] <IDENTIFIER> "." "LIKE" ...
[java] <IDENTIFIER> "." "ESCAPE" ...
[java] <IDENTIFIER> "." "BETWEEN" ...
[java] <IDENTIFIER> "." "NULL" ...
[java] <IDENTIFIER> "." "AVG" ...
[java] <IDENTIFIER> "." "MIN" ...
[java] <IDENTIFIER> "." "MAX" ...
[java] <IDENTIFIER> "." "SUM" ...
[java] <IDENTIFIER> "." "COUNT" ...
[java] <IDENTIFIER> "." "OR" ...
[java] <IDENTIFIER> "." "AND" ...
[java] <IDENTIFIER> "." "NOT" ...
[java] <IDENTIFIER> "." "CONCAT" ...
[java] <IDENTIFIER> "." "SUBSTRING" ...
[java] <IDENTIFIER> "." "TRIM" ...
[java] <IDENTIFIER> "." "LOWER" ...
[java] <IDENTIFIER> "." "UPPER" ...
[java] <IDENTIFIER> "." "LEADING" ...
[java] <IDENTIFIER> "." "TRAILING" ...
[java] <IDENTIFIER> "." "BOTH" ...
[java] <IDENTIFIER> "." "LENGTH" ...
[java] <IDENTIFIER> "." "LOCATE" ...
[java] <IDENTIFIER> "." "ABS" ...
[java] <IDENTIFIER> "." "SQRT" ...
[java] <IDENTIFIER> "." "MOD" ...
[java] <IDENTIFIER> "." "SIZE" ...
[java] <IDENTIFIER> "." "CURRENT_DATE" ...
[java] <IDENTIFIER> "." "CURRENT_TIME" ...
[java] <IDENTIFIER> "." "CURRENT_TIMESTAMP" ...
[java] <IDENTIFIER> "." "SELECT" ...
[java] <IDENTIFIER> "." "DISTINCT" ...
[java] <IDENTIFIER> "." "FROM" ...
[java] <IDENTIFIER> "." "UPDATE" ...
[java] <IDENTIFIER> "." "DELETE" ...
[java] <IDENTIFIER> "." "WHERE" ...
[java] <IDENTIFIER> "." "GROUP" ...
[java] <IDENTIFIER> "." "BY" ...
[java] <IDENTIFIER> "." "HAVING" ...
[java] <IDENTIFIER> "." "AS" ...
[java] <IDENTIFIER> "." "LEFT" ...
[java] <IDENTIFIER> "." "OUTER" ...
[java] <IDENTIFIER> "." "INNER" ...
[java] <IDENTIFIER> "." "JOIN" ...
[java] <IDENTIFIER> "." "FETCH" ...
[java] <IDENTIFIER> "." "IN" ...
[java] <IDENTIFIER> "." "SET" ...
[java] <IDENTIFIER> "." "OBJECT" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "." ...
[java] <IDENTIFIER> "." <IDENTIFIER> "*" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "/" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "+" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "-" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ")" ...
[java] <STRING_LITERAL> ...
[java] "SELECT" ...
[java] "EXISTS" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "=" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "+" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "-" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">="
<DECIMAL_LITERAL> ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">="
<INTEGER_LITERAL> ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" ":" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "?" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "db:" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" <IDENTIFIER> "." ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "(" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "LENGTH" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "LOCATE" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "ABS" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "SQRT" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "MOD" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "SIZE" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "AVG" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "MAX" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "MIN" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "SUM" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "COUNT" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "SELECT" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "ANY" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "SOME" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "ALL" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "<" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "<=" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "<>" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" <STRING_LITERAL> ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "CONCAT" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "SUBSTRING" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "TRIM" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "LOWER" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "UPPER" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "CURRENT_DATE" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">=" "CURRENT_TIME" ...
[java] <IDENTIFIER> "." <IDENTIFIER> ">="
"CURRENT_TIMESTAMP" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "NOT" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "BETWEEN" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "LIKE" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "IN" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "IS" ...
[java] <IDENTIFIER> "." <IDENTIFIER> "MEMBER" ...
[java]
[java] at
org
.apache.cayenne.ejbql.parser.EJBQL.generateParseException(EJBQL.java:
9409)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.jj_consume_token(EJBQL.java:9286)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.conditional_primary(EJBQL.java:
1931)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.conditional_factor(EJBQL.java:
1909)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.conditional_term(EJBQL.java:1774)
[java] at
org
.apache.cayenne.ejbql.parser.EJBQL.conditional_expression(EJBQL.java:
1736)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.conditional_primary(EJBQL.java:
1926)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.conditional_factor(EJBQL.java:
1909)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.conditional_term(EJBQL.java:1774)
[java] at
org
.apache.cayenne.ejbql.parser.EJBQL.conditional_expression(EJBQL.java:
1736)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.conditional_primary(EJBQL.java:
1926)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.conditional_factor(EJBQL.java:
1909)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.conditional_term(EJBQL.java:1774)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.conditional_term(EJBQL.java:1787)
[java] at
org
.apache.cayenne.ejbql.parser.EJBQL.conditional_expression(EJBQL.java:
1736)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.where_clause(EJBQL.java:1583)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.select_statement(EJBQL.java:67)
[java] at
org.apache.cayenne.ejbql.parser.EJBQL.parseQuery(EJBQL.java:39)
[java] at org.apache.cayenne.ejbql.parser.EJBQL
$EJBQLDefaultParser.compile(EJBQL.java:28)
[java] ... 37 more
And if I regex replace '= null' with 'IS NULL' and '!= null' with 'IS
NOT NULL' problems persist. It also doesn't like false and true
obviously.... so it seems to me that expression.toEJBQL("a") is not
transforming to a usable expression? i.e., it's not transforming it to
something that succeeds in parsing when performing the query.
Any clues?
Thanks.
with regards,
--Lachlan Deck
This archive was generated by hypermail 2.0.0 : Wed Aug 13 2008 - 16:43:06 EDT