Re: Bug with EJBQL query referencing two subclasses?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Sep 14 2010 - 21:41:40 UTC

  • Next message: Andrus Adamchik: "Re: Cayenne error while committing CLOB on Oracle"

    Hi Dave,

    Will be very happy if you can dig to the cause of this issue.

    EJBQLQuery parsing into SQL starts at org.apache.cayenne.access.jdbc.EJBQLAction. Cayenne walks EJBQL syntax tree, calling visitor callback methods and occasionally switching the visitor object. You may start debugging from EJBQLSelectTranslator (a top level visitor). Look for uses of EJBQLTranslationContext.makeEntityQualifierMarker() method. Those are the places where a placeholder for entity qualifier is created, and a qualifier is later inserted.

    Cheers,
    Andrus

    On Sep 14, 2010, at 10:54 AM, Dave Lamy wrote:

    > Hello Cayenne gurus--
    >
    > I hit a SQL syntax problem yesterday while trying to issue a EJBQL query to
    > determine value uniqueness within a given parent "context". The EJBQL query
    > is:
    >
    > SELECT COUNT(distinct a.id) FROM Clip AS a JOIN a.timeline b WHERE a.name =
    > ?1 AND b = ?2 [{foo,200}]
    >
    > The interesting part about this structure is the both Clip and Timeline (the
    > target class of the .timeline association) both descend from a common
    > abstract parent class. The query is attempting to determine whether the
    > name "foo" is unique within the context of the clip's timeline, which has a
    > PK of 200.
    >
    > Here is the resulting SQL:
    >
    > SELECT COUNT(DISTINCT t0.ID) AS sc0 FROM TIMELINE_SEGMENT t0 INNER JOIN
    > TIMELINE_SEGMENT t1 ON (t0.TIMELINE_ID = t1.ID) WHERE *t0.SEGMENT_TYPE = ?
    > t1.SEGMENT_TYPE = ?* AND t0.NAME = ? AND t1.ID = ? [bind: 1:'CLIP',
    > 2:'TIMELINE', 3:'foo', 4:200]
    >
    > As you can see, the SQL generation skips an "AND" in between the two
    > qualifier clauses. The rest of the SQL looks perfect, but this missing AND
    > is obviously messing things up.
    >
    > I upgraded to 3.1 and the problem still occurs. I can submit a JIRA on this
    > but would like the opportunity to investigate and fix it.. I need this code
    > to work now and so can run with a patched version until a fix is formally
    > introduced. So, I was hoping that someone could give me a starting point to
    > look. What classes would probably be involved in this clause creation?
    >
    > Thanks for any help with resolving this one--
    >
    > Dave



    This archive was generated by hypermail 2.0.0 : Tue Sep 14 2010 - 21:42:07 UTC