RE: double inner join

From: Dave Merrin (dmerri..pasystems.co.uk)
Date: Fri Oct 14 2005 - 07:57:06 EDT

  • Next message: Ahmed Mohombe: "Re: ANNOUNCEMENT: Click 0.13 Released"

    Hi Andrus,

    Thanks for that. It worked a treat! I had to create a new DbRelationship as
    part of the ObjRelationship and copy across the properties but then it
    worked.

    I'm not sure how you'd get Cayenne to do this work instead but it would be
    good if somebody could work it out.

    For now I'll have to make do with this solution.

    Cheers,

    Dave

    > -----Original Message-----
    > From: Andrus Adamchik [mailto:andru..bjectstyle.org]
    > Sent: 07 October 2005 18:56
    > To: cayenne-use..bjectstyle.org
    > Subject: Re: double inner join
    >
    >
    > Don't have time to write a complete example, but here is an outline:
    >
    > 1. Use DataContext.getEntityResolver() to get to the mapping in runtime.
    >
    > 2. Create new ObjEntity based on the target entity in the
    > relationship (i.e. based on Kitten). E.g.:
    >
    > ObjEntity kitten = entityResolver.lookupObjEntity("Kitten");
    >
    > ObjEntity clone = new ObjEntity("KittenHack");
    >
    > // we don't care what the class name is as long as there is no
    > conflict
    > clone.setClassName("java.lang.Object");
    > clone.setDbEntityName(kitten.getDbEntityName());
    >
    > // copy attributes but not relationships...
    > Iterator attributes = getDeclaredAttributes().iterator();
    > while (attributes.hasNext()) {
    > ObjAttribute attribute = (ObjAttribute) attributes.next();
    >
    > // just copy the name, type and DB Attribute mapping
    > }
    >
    > // register with DataMap
    > kitten.getDataMap().addObjEntity(clone);
    >
    >
    > 3. Create relationship from source entity (Cat) to the new entity
    > (KittenHack) with a name different from original relationship (e.g.
    > 'kittenHacks').
    >
    > You should be good to go...
    >
    > Andrus
    >
    >
    > On Oct 7, 2005, at 4:50 AM, Dave Merrin wrote:
    >
    > > that sounds like it might be possible. Is it possible to create a new
    > > mapping based on an existing mapping on the fly (i.e. in code). How
    > > do I
    > > then go about using the new mapping to query the database?
    > >
    > > I've had a quick look through the ObjEntity class but I'm not sure
    > > how to
    > > run a query using it.
    > >
    > > Cheers,
    > >
    > > Dave
    > >
    > >
    > >> -----Original Message-----
    > >> From: Cris Daniluk [mailto:cris.danilu..mail.com]
    > >> Sent: 06 October 2005 19:53
    > >> To: cayenne-use..bjectstyle.org
    > >> Subject: Re: double inner join
    > >>
    > >>
    > >> I thought I saw a post a while back about someone doing this by
    > >> creating another ObjEntity ref to the table or something like that?
    > >>
    > >> I could be smoking crack...
    > >>
    > >> Cris
    > >>
    > >> On 10/6/05, Andrus Adamchik <andru..bjectstyle.org> wrote:
    > >>
    > >>> There was a proposal to add that, but it has never materialized into
    > >>> code (maybe someday)
    > >>>
    > >>> http://www.objectstyle.org/cayenne/lists/cayenne-devel/
    > >>> 2003/09/0096.html
    > >>>
    > >>> So I guess for now SQLTemplate is the only way.
    > >>>
    > >>> Andrus
    > >>>
    > >>>
    > >>> On Oct 6, 2005, at 12:47 PM, Dave Merrin wrote:
    > >>>
    > >>>
    > >>>> i'd like to accomplish something like this using Expresssions:
    > >>>>
    > >>>> from Cat cat
    > >>>> inner join cat.kittens as kittens0
    > >>>> inner join cat.kittens as kittens1
    > >>>> where kittens0.name = 'Fred'
    > >>>> and kittens1.name = 'Amy'
    > >>>>
    > >>>> which would find cats that have at least two kittens, one named
    > >>>> fred and
    > >>>> another amy.
    > >>>>
    > >>>> How do I do this using Expressions?
    > >>>>
    > >>>> Cheers,
    > >>>>
    > >>>> Dave
    > >>>>
    > >>>>
    > >>>>
    > >>>
    > >>>
    > >>>
    > >>
    > >>
    > >
    > >
    > >
    >



    This archive was generated by hypermail 2.0.0 : Fri Oct 14 2005 - 07:59:36 EDT