You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by "Garcia Corral, Josep" <jo...@tecsidel.es> on 2008/05/28 15:45:53 UTC

getArray matching specific criteria?

Hello,

Having this:

Class Master {
            int id;
...
};

Class Detail {
            int id_master;
...
            String data;
};

I cannot figure out how to perform a SelectQuery to obtain detail records matching a condition, equivalent to a pseudocode SQL sentence like this:

Select Detail.* from Detail, Master where Detail.id_master = myMasterInstance_id and data = other_value;

In pseudocode Java, I would like to have:

Master myMaster;
...
List<Detail> list = myMaster.getDetailArray( data field matching specific criteria);

Is it a good practice to do it via SelectQuery, or is it better to do this via SQLTemplate?

Josep


Re: getArray matching specific criteria?

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi there,

you need an expression matching on relationship. E.g:

ExpressionFactory.matchExpression("master", masterObject);

where "master" is the name of relationship.

Andrus


On May 28, 2008, at 4:45 PM, Garcia Corral, Josep wrote:

> Hello,
>
> Having this:
>
> Class Master {
>            int id;
> ...
> };
>
> Class Detail {
>            int id_master;
> ...
>            String data;
> };
>
> I cannot figure out how to perform a SelectQuery to obtain detail  
> records matching a condition, equivalent to a pseudocode SQL  
> sentence like this:
>
> Select Detail.* from Detail, Master where Detail.id_master =  
> myMasterInstance_id and data = other_value;
>
> In pseudocode Java, I would like to have:
>
> Master myMaster;
> ...
> List<Detail> list = myMaster.getDetailArray( data field matching  
> specific criteria);
>
> Is it a good practice to do it via SelectQuery, or is it better to  
> do this via SQLTemplate?
>
> Josep
>