Re: Double inner joins (again)

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Feb 15 2006 - 13:35:52 EST

  • Next message: Dov Rosenberg: "Oracle Fetch Limit Issue"

    I opened an improvement task in jira:

    http://objectstyle.org/jira/secure/ViewIssue.jspa?key=CAY-447

    I need to investigate that when I have more time.

    Andrus

    On Feb 14, 2006, at 6:18 AM, Dave Merrin wrote:
    > Hi,
    >
    > I've got some code which sets up new objects and relationships to
    > allow me
    > to do double inner joins. I've tried some code which goes a little
    > further
    > than originally planned to produce the following sql:
    >
    > SELECT DISTINCT
    > t0.create_by, t0.create_timestamp, t0.instance, t0.item_id, t0.job_id,
    > t0.name, t0.purge_flag, t0.update_by, t0.update_timestamp,
    > t0.item_state_id,
    > t0.item_type_id, t0.process_state_id
    > FROM
    > item t0,
    > item_meta_data t1,
    > meta_type t2,
    > item_meta_data t3,
    > meta_type t4
    > WHERE
    > t0.item_id = t1.item_id AND
    > t1.meta_type_id = t2.meta_type_id AND
    > t0.item_id = t3.item_id AND
    > t1.meta_type_id = t4.meta_type_id AND
    >
    > ((t1.string_value = ?) AND (t2.name = ?) AND (t3.string_value = ?) AND
    > (t4.name = ?)) [bind: 'Cyan', 'PageColour', '12', 'PageNumber']
    >
    > Unfortunately this isn't the required result. The final join should
    > use t3
    > and t4 rather than t1 and t4:
    >
    > t3.meta_type_id = t4.meta_type_id AND
    >
    >
    > I've had a look at the cayenne code and it seems to come down to the
    > following (from SelectTranslator.java) :
    >
    > private void appendJoins(StringBuffer queryBuf, int index) {
    > DbRelationship rel = (DbRelationship) dbRelList.get(index);
    > String srcAlias = aliasForTable((DbEntity)
    > rel.getSourceEntity());
    > String targetAlias = (String) aliasLookup.get(rel);
    >
    > The source alias is just being retrieved using the source entity. I
    > would
    > really prefer it to take notice of the relationship as well so as to
    > retrieve the correct alias.
    >
    > I'm not entirely sure how to do this but would it be possible? I
    > know it's
    > not really a bug but it would help me a lot.
    >
    > Cheers,
    >
    > Dave
    >
    >



    This archive was generated by hypermail 2.0.0 : Wed Feb 15 2006 - 13:35:54 EST