db-ojb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Braeuchi <jbraeu...@gmx.ch>
Subject Re: Collection Query, continuation
Date Wed, 01 Jun 2005 17:26:51 GMT
hi kirill,

you should try using the path class hint:

Criteria crit = new Criteria();
crit.addLike("reactions.name", rName);
QueryByCriteria query = new QueryByCriteria(Model.class, crit1);
query.addPathClass("reactions", BidirectionalReaction.class);

in this case ojb will only use BidirectionalReaction when processing the 
relationship "reactions".

there's a test case called PathTest for this feature.

jakob

Kirill Petrov schrieb:
> Hello everybody,
> 
> Recently, I asked a question how can a query an object having a property 
> which is a collection of objects. I received an answer, so, now my query 
> looks like this:
> 
> public static Collection findModelsByReactionsName(String rName) {
> 
>     PersistenceBroker broker = 
> PersistenceBrokerFactory.defaultPersistenceBroker();
> 
>     try{
>       Criteria crit = new Criteria();
>       crit.addLike("reactions.name", rName);
>       QueryByCriteria query = new QueryByCriteria(Model.class, crit);
>       return broker.getCollectionByQuery(query);
>     } finally {
>       broker.close();
>     }
>   }
> 
> Now, I have another problem. There are several subclasses of Reaction. 
> Those subclasses of course have their own properties. For example, 
> "BidirectionalReaction" has a property "reverseRate". I want to query 
> the models by this property which implies that I am looking only for the 
> models that have BidirectionalReactions in them. But I don't know how to 
> do that. If I just specify "reactions.reverseRate" in the query, OJB 
> generates SQL that would try to query using all the possibe subclasses. 
> The SQL of course fails since only one table would have a column 
> corresponding to reverseRate.
> 
> How do I write such a query?
> 
> thanks a lot,
> 
> Kirill
> 
> PS
> 
> Here is explanation of my object model:
> 
> I have an object model in which there are two objects: Model and
> Reactiont. This is basically n to m relationship. Model can have a 
> number of Reactions. Reactions can be in a number of Models.
> In Java this is implemented by a Collection property in Model class.
> 
> I want to construct a query that allows me to find all the models that
> have a particular reaction in them.
> 
> 
> 
> ---------------------------------------------------------------------
> 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


Mime
View raw message