Re: Bug with EJBQL query referencing two subclasses?

From: Dave Lamy (davelam..mail.com)
Date: Mon Sep 20 2010 - 20:56:10 UTC

  • Next message: Mike Kienenberger: "Re: vppconfig - cgen question"

    Hey Andrus--

    Found and fixed. Thanks for the hint on where to look, saved me a lot of
    time. The EJBQLJoinAppender was assuming that the entity qualifier buffer
    was going to be empty, so I swiped a couple of lines from
    EJBQLSelectTranslator.visitWhere that checks the existing length of the
    buffer and appends an AND in if length > 0. Works like a charm.

    Patch attached.

    Dave

    On Wed, Sep 15, 2010 at 10:28 AM, Dave Lamy <davelam..mail.com> wrote:

    > Thanks Andrus, I'll let you know what I find.
    >
    > Dave
    >
    >
    > On Tue, Sep 14, 2010 at 4:41 PM, Andrus Adamchik <andru..bjectstyle.org>wrote:
    >
    >> 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 : Mon Sep 20 2010 - 20:56:59 UTC