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 Jair da Silva Ferreira Júnior <j2...@amazon.com.br> on 2004/01/08 16:34:46 UTC
ojb query question
Hi,
I am using ojb1.0_rc5, ODMG api with OJB queries, mysql4 (innodb tables)
in Linux Red Hat 7.3 (kernel 2.4.20-20.7).
How can I run a query that returns objects from a different class than
the class to search from? For example:
class Person{
int id;
String name;
//rest of the class ommited
}
class House{
int id;
String name;
int ownerId;
Person owner; //reference to Person
//rest of the class ommited
}
The House class has a reference to the Person class.
I want to build a query like this:
Criteria c=new Criteria();
c.addEqualTo("name","home");
QueryByCriteria query=QueryFactory.newQuery(House.class,c);
I want the query to return objects of the Person class using the
reference from House (owner atribute).
Something like:
query.setSelectAttribute("owner",true); //the true parameter
is to return distinct objects
or
broker.getCollectionByQuery(query,"owner",true);
I looked for a similar method in OJB api and docs and couldn't
find one. Is there such a similar method or is there anyway I can achieve
the same result?
I know that I can get House objects from the query and then get the
Person objects I need in a loop, but that would make performance suffer in
my scenario.
Please, notice that I don't have a collection of Houses in Person
because that would also make performace suffer in my scenario.
Any help would be appreciated.
Thanks,
Jair Jr
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: ojb query question
Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi jair,
if there's no reference from person to house you can't build a simple
query. but you may use a query with a subquery. please have a look at
QueryTest#testSubQuery4
hth
jakob
Jair da Silva Ferreira Júnior wrote:
> Hi,
> I am using ojb1.0_rc5, ODMG api with OJB queries, mysql4 (innodb tables)
> in Linux Red Hat 7.3 (kernel 2.4.20-20.7).
> How can I run a query that returns objects from a different class than
> the class to search from? For example:
>
> class Person{
> int id;
> String name;
>
> //rest of the class ommited
> }
>
> class House{
> int id;
> String name;
>
> int ownerId;
> Person owner; //reference to Person
>
> //rest of the class ommited
> }
>
> The House class has a reference to the Person class.
>
> I want to build a query like this:
> Criteria c=new Criteria();
> c.addEqualTo("name","home");
> QueryByCriteria query=QueryFactory.newQuery(House.class,c);
>
> I want the query to return objects of the Person class using the
> reference from House (owner atribute).
> Something like:
> query.setSelectAttribute("owner",true); //the true parameter
> is to return distinct objects
> or
> broker.getCollectionByQuery(query,"owner",true);
>
> I looked for a similar method in OJB api and docs and couldn't
> find one. Is there such a similar method or is there anyway I can achieve
> the same result?
>
> I know that I can get House objects from the query and then get the
> Person objects I need in a loop, but that would make performance suffer in
> my scenario.
> Please, notice that I don't have a collection of Houses in Person
> because that would also make performace suffer in my scenario.
>
> Any help would be appreciated.
>
> Thanks,
> Jair Jr
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org