EJBQL with aggregrate function render to Java List

From: Steve Wells (websystem..mail.com)
Date: Mon Jan 11 2010 - 20:42:31 EST

  • Next message: Steve Wells: "Re: EJBQL with aggregrate function render to Java List"

    Hi All,

    I have an EJBQL query selecting a grouped value from a master table
    (Category.name) and the count of detail rows for each grouping (ie count of
    the Category.questions), so I get results:
    cat1, 5
    cat2, 3
    cat3, 10
    etc...

    Ideally what I need to do is get the results into a java List<?>, so I was
    hoping (by waving magic Cayenne wand!) that this would work:

    "select new CategorySummary(c.name, count(q)) from Category c left join
    c.questions q group by c.name" returning a List<CategorySummary>...but I
    can't get it working. Is there a prescribed approach for this?

    At the moment I get this:

    java.lang.NullPointerException
            at org.apache.cayenne.ejbql.parser.Compiler.compileEntityResult(Compiler.java:219)
            at org.apache.cayenne.ejbql.parser.Compiler.compile(Compiler.java:200)
            at org.apache.cayenne.ejbql.parser.EJBQL$EJBQLDefaultParser.compile(EJBQL.java:30)
            at org.apache.cayenne.query.EJBQLQuery.getExpression(EJBQLQuery.java:122)
            at org.apache.cayenne.query.EJBQLQueryMetadata.resolve(EJBQLQueryMetadata.java:38)
            at org.apache.cayenne.query.EJBQLQuery.getMetaData(EJBQLQuery.java:66)
            at org.apache.cayenne.util.ObjectContextQueryAction.<init>(ObjectContextQueryAction.java:79)
            at org.apache.cayenne.access.DataContextQueryAction.<init>(DataContextQueryAction.java:48)
            at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1278)
            at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1267)
            at org.apache.click.extras.cayenne.CayenneTemplate.performQuery(CayenneTemplate.java:276)

    CategorySummary.java:

    CategorySummary {
        private String name;
        private Number count;

    plus getters and setters

    The EJB spec says you can do something like:

    SELECT NEW com.acme.example.CustomerDetails(c.id, c.status, o.count)
    FROM Customer c JOIN c.orders o
    WHERE o.count > 100

    Does Cayenne support this?

    Thanks for any help,

    Steve



    This archive was generated by hypermail 2.0.0 : Mon Jan 11 2010 - 20:43:08 EST