Re: Getting unmapped PK using EJBQL

From: Dave Dombrosky (dombr..mail.com)
Date: Fri Oct 03 2008 - 12:35:14 EDT

  • Next message: Marc Gabriel-Willem: "Multiple queries using the same DB session !"

    Looks like I was slightly wrong about what's happening here. I can
    get the PK just fine if i use the "a.b" path expression I talked about
    in the previous post. However, there is a String that is getting
    returned in the query, but not getting set in the Object[] that is
    returned from performQuery().

    The beginning part of the query ends up looking like this:
        SELECT COUNT(*) AS sc0, t1.foo_id, t2.name AS sc1 FROM...

    Yet the sc1 result always ends up being null, even though when I run
    the query directly through the DB the column is always not null.

    This is starting to look like a bug at this point. I'll add an issue
    in JIRA if I discover more.

    -Dave

    On Thu, Oct 2, 2008 at 4:43 PM, Dave Dombrosky <dombr..mail.com> wrote:
    > What is the preferred way to get the PK (or any unmapped column) when
    > using an EJBQL query?
    >
    > If I have a path expression (a.b) that references a table, then the
    > query runs to completion. The only problem here is that the PK column
    > doesn't get the sc* alias, so it doesn't get added to the returned
    > Object[]. If I try the same path but with ".id" (a.b.id) to reference
    > the PK column, then i get the following error:
    >
    > java.lang.IllegalStateException: Invalid path component: id
    > Stack trace
    > * org.apache.cayenne.access.jdbc.EJBQLPathTranslator.processLastPathComponent(EJBQLPathTranslator.java:187)
    > * org.apache.cayenne.access.jdbc.EJBQLPathTranslator.visitPath(EJBQLPathTranslator.java:74)
    > * org.apache.cayenne.ejbql.parser.EJBQLPath.visitChild(EJBQLPath.java:72)
    > * org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
    > * org.apache.cayenne.access.jdbc.EJBQLSelectColumnsTranslator.visitPath(EJBQLSelectColumnsTranslator.java:105)
    > * org.apache.cayenne.ejbql.parser.EJBQLPath.visitNode(EJBQLPath.java:67)
    > * org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:60)
    > * org.apache.cayenne.ejbql.parser.SimpleNode.visitChild(SimpleNode.java:84)
    > * org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
    >
    > Then if I try prefixing the path expression with "db" (db:a.b.id) I
    > get the following error:
    >
    > java.lang.IllegalStateException: Invalid path component: id
    > Stack trace
    > * org.apache.cayenne.access.jdbc.EJBQLPathTranslator.processLastPathComponent(EJBQLPathTranslator.java:187)
    > * org.apache.cayenne.access.jdbc.EJBQLPathTranslator.visitPath(EJBQLPathTranslator.java:74)
    > * org.apache.cayenne.ejbql.parser.EJBQLPath.visitChild(EJBQLPath.java:72)
    > * org.apache.cayenne.ejbql.parser.EJBQLDbPath.visitChild(EJBQLDbPath.java:31)
    > * org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
    > * org.apache.cayenne.access.jdbc.EJBQLSelectColumnsTranslator.visitPath(EJBQLSelectColumnsTranslator.java:105)
    > * org.apache.cayenne.ejbql.parser.EJBQLPath.visitChild(EJBQLPath.java:72)
    > * org.apache.cayenne.ejbql.parser.EJBQLDbPath.visitChild(EJBQLDbPath.java:31)
    > * org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
    >
    > It appears to be using a db-path parser in this last case, but I still
    > can't access the column. What am I doing wrong?
    >
    > -Dave
    >



    This archive was generated by hypermail 2.0.0 : Fri Oct 03 2008 - 17:37:34 EDT