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 "Beeker, Andreas" <EX...@wwk.de> on 2004/11/30 15:39:09 UTC

criteria/query by object

Hi all,

I retrieved an object (class TestRun) by an existing Iterator-Query.
Now I want to find all objects of class TestStep which reference
the former TestRun-object. My primary keys are all anonymous keys and
also the foreign key of class TestStep (attribute "testRun"/
anonymous key "testRunId").

I've managed to find the right objects by this criteria:
TestRun run = ...;
Criteria crit = new Criteria();
crit.addEqualTo("testRun", new Identity(run,
broker).getPrimaryKeyValues()[0]);

I've also tried to use a subquery, which lead to an ClassCastException
in SqlQueryStatement, because it assumes to get a QueryByCriteria:
crit.addIn("testRun", new QueryByIdentity(run));

My OJB version is 1.0.1 and I only use the PB-API. I've seen that there
was a PB-extension for JDO (Criteria.addIdentityEqualTo) which could
solve
the problem.
Is this the right way or is there another more convienent way to define
the criteria (... without knowing how many keys must be specified)?

Thanks,
Andreas.

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: criteria/query by object

Posted by "Robert r. Sanders" <ro...@ipov.net>.
If your TestStep object has a field testRun then the query should only 
need to:

TestRun myTestRun = ...;
Criteria criteria = new Criteria();
criteria.addEqualTo("testRun", myTestRun);
....
OJB will take care of all the identity lookups for you (as long as the 
configuration xml is correct).


Beeker, Andreas wrote:

>Hi all,
>
>I retrieved an object (class TestRun) by an existing Iterator-Query.
>Now I want to find all objects of class TestStep which reference
>the former TestRun-object. My primary keys are all anonymous keys and
>also the foreign key of class TestStep (attribute "testRun"/
>anonymous key "testRunId").
>
>I've managed to find the right objects by this criteria:
>TestRun run = ...;
>Criteria crit = new Criteria();
>crit.addEqualTo("testRun", new Identity(run,
>broker).getPrimaryKeyValues()[0]);
>
>I've also tried to use a subquery, which lead to an ClassCastException
>in SqlQueryStatement, because it assumes to get a QueryByCriteria:
>crit.addIn("testRun", new QueryByIdentity(run));
>
>My OJB version is 1.0.1 and I only use the PB-API. I've seen that there
>was a PB-extension for JDO (Criteria.addIdentityEqualTo) which could
>solve
>the problem.
>Is this the right way or is there another more convienent way to define
>the criteria (... without knowing how many keys must be specified)?
>
>Thanks,
>Andreas.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-user-help@db.apache.org
>
>  
>

-- 
    Robert r. Sanders
    Chief Technologist
    iPOV
    www.ipov.net


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org