You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Goncalo Luiz <ge...@rnl.ist.utl.pt> on 2003/04/28 02:30:03 UTC

QueryByCriteria

Hi,

How can I specify an object's field instead of a BD's column in criteria?
In some cases I may have
For example, if I have the class

class A {
private int id;
private B b;

//getters and setters ahead...
}

class B {
private String name;
}

In OQL I'd do something like:
"select a from " + A.class.getName() + "where b.name = $1"
to get the object a where the b's name is the object bound to $1.

However in Criteria I'm only able to compare objects with columns of a
table, as far as I know.
Is it possible to do querys like in this OQL example ?

Gonçalo D. Luiz (gedl@rnl.ist.utl.pt) | Tlm: 933 480 059



Re: QueryByCriteria

Posted by Luis Cruz <le...@netcabo.pt>.
Using criteria you would do something of the sort to obtain the same
results as the OQL query you described:

    Criteria crit = new Criteria();
    crit.addEqualTo("b.name", "Value of string you would bind to $1");
    Query q = QueryFactory.newQuery(A.class, crit);

    Collection result = broker.getCollectionByQuery(q);

Cheers,
Luis Cruz


On Mon, 2003-04-28 at 01:30, Goncalo Luiz wrote:
> Hi,
> 
> How can I specify an object's field instead of a BD's column in criteria?
> In some cases I may have
> For example, if I have the class
> 
> class A {
> private int id;
> private B b;
> 
> //getters and setters ahead...
> }
> 
> class B {
> private String name;
> }
> 
> In OQL I'd do something like:
> "select a from " + A.class.getName() + "where b.name = $1"
> to get the object a where the b's name is the object bound to $1.
> 
> However in Criteria I'm only able to compare objects with columns of a
> table, as far as I know.
> Is it possible to do querys like in this OQL example ?
> 
> Gonçalo D. Luiz (gedl@rnl.ist.utl.pt) | Tlm: 933 480 059
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>