You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by "Diethelm Guallar, Gonzalo" <Go...@sonda.com> on 2001/05/12 01:08:13 UTC

Criteria, join and columns with same names

If I use Criteria to do a join between two tables,
what is the standard mechanism to differentiate
between columns of same name and different tables?
For example:

        Criteria ct = new Criteria();
        ct.addSelectColumn(TonePeer.COLX);
        ct.addSelectColumn(TtwoPeer.COLX);
        ct.add(TonePeer.COLY, valueY);
        ct.add(TtwoPeer.COLZ, valueZ);
        ct.addJoin(TonePeer.COLP, TtwoPeer.COLP);
        ct.addJoin(TonePeer.COLQ, TtwoPeer.COLQ);
        Vector v = TonePeer.doSelect(ct);

In this example, the values for COLX in each table are
different.

How do I ask for COLX in Tone, or COLX in Ttwo, from v?
In fact, what exactly is the type of each object that
gets placed in Vector v Are they Tone objects? Also,
is it any different if I do

        Vector v = TtwoPeer.doSelect(ct);

In this case, the type of each object in Vector v would
be Ttwo? And if this is the case, how would I get the
values for all of Tone's columns placed in the select?

Thanks,


-- 
Gonzalo A. Diethelm
gonzalo.diethelm@sonda.com

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: Criteria, join and columns with same names

Posted by John McNally <jm...@collab.net>.
If you are using torque generated objects with a foreign key arrangement 

<table TONE>
<fk TTWO>
    <reference COLP COLP/>
    <reference COLQ COLQ/>
</fk>
</table>


>         Criteria ct = new Criteria();
>         ct.add(TonePeer.COLY, valueY);
>         ct.add(TtwoPeer.COLZ, valueZ);
>         Vector v = TonePeer.doSelectJoinTtwo(ct);

would provide you with a List of Tone objects.  A Tone object has a
method getTtwo() which returns the Ttwo object.

john mcnally


"Diethelm Guallar, Gonzalo" wrote:
> 
> If I use Criteria to do a join between two tables,
> what is the standard mechanism to differentiate
> between columns of same name and different tables?
> For example:
> 
>         Criteria ct = new Criteria();
>         ct.addSelectColumn(TonePeer.COLX);
>         ct.addSelectColumn(TtwoPeer.COLX);
>         ct.add(TonePeer.COLY, valueY);
>         ct.add(TtwoPeer.COLZ, valueZ);
>         ct.addJoin(TonePeer.COLP, TtwoPeer.COLP);
>         ct.addJoin(TonePeer.COLQ, TtwoPeer.COLQ);
>         Vector v = TonePeer.doSelect(ct);
> 
> In this example, the values for COLX in each table are
> different.
> 
> How do I ask for COLX in Tone, or COLX in Ttwo, from v?
> In fact, what exactly is the type of each object that
> gets placed in Vector v Are they Tone objects? Also,
> is it any different if I do
> 
>         Vector v = TtwoPeer.doSelect(ct);
> 
> In this case, the type of each object in Vector v would
> be Ttwo? And if this is the case, how would I get the
> values for all of Tone's columns placed in the select?
> 
> Thanks,
> 
> --
> Gonzalo A. Diethelm
> gonzalo.diethelm@sonda.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-dev-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org