Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package strimillinn.temp;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.query.EJBQLQuery;
import strimillinn.core.StrimillinnCore;
import strimillinn.core.model.Login;
import strimillinn.core.model.User;
/**
* Demonstrates a potential bug in Cayenne EJBQL generation when generating EJBQL from expressions with outer joins.
*/
public class EJBQLOuterJoinErrorTestCase {
public static void main( String[] args ) {
ObjectContext objectContext = StrimillinnCore.newContext();
Expression exp = Login.USER.outer().dot( User.NAME ).eq( "Hugi Þórðarson" );
String ejbqlString = "select a.uniqueID from Login a where " + exp.toEJBQL( "a" );
EJBQLQuery query = new EJBQLQuery( ejbqlString );
objectContext.performQuery( query ); // Error occurs here, during the query.
}
}
Exception in thread "main" org.apache.cayenne.ejbql.EJBQLException: [v.4.0.M2 Feb 26 2015 08:16:32] Error parsing EJB QL statement
at org.apache.cayenne.ejbql.parser.EJBQL$EJBQLDefaultParser.compile(EJBQL.java:33)
at org.apache.cayenne.query.EJBQLQuery.getExpression(EJBQLQuery.java:176)
at org.apache.cayenne.query.EJBQLQueryMetadata.resolve(EJBQLQueryMetadata.java:38)
at org.apache.cayenne.query.EJBQLQuery.getMetaData(EJBQLQuery.java:88)
at org.apache.cayenne.util.ObjectContextQueryAction.<init>(ObjectContextQueryAction.java:81)
at org.apache.cayenne.access.DataContextQueryAction.<init>(DataContextQueryAction.java:49)
at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:985)
at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:974)
at strimillinn.temp.EJBQLOuterJoinErrorTestCase.main(EJBQLOuterJoinErrorTestCase.java:23)
Caused by: org.apache.cayenne.ejbql.parser.ParseException: Encountered " <IDENTIFIER> "a "" at line 1, column 38.
Was expecting:
"(" ...
at org.apache.cayenne.ejbql.parser.EJBQL.generateParseException(EJBQL.java:9469)
at org.apache.cayenne.ejbql.parser.EJBQL.jj_consume_token(EJBQL.java:9348)
at org.apache.cayenne.ejbql.parser.EJBQL.conditional_primary(EJBQL.java:1934)
at org.apache.cayenne.ejbql.parser.EJBQL.conditional_factor(EJBQL.java:1912)
at org.apache.cayenne.ejbql.parser.EJBQL.conditional_term(EJBQL.java:1776)
at org.apache.cayenne.ejbql.parser.EJBQL.conditional_expression(EJBQL.java:1738)
at org.apache.cayenne.ejbql.parser.EJBQL.where_clause(EJBQL.java:1585)
at org.apache.cayenne.ejbql.parser.EJBQL.select_statement(EJBQL.java:69)
at org.apache.cayenne.ejbql.parser.EJBQL.parseQuery(EJBQL.java:41)
at org.apache.cayenne.ejbql.parser.EJBQL$EJBQLDefaultParser.compile(EJBQL.java:30)
... 8 more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment