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 ol...@ppi.de on 2003/08/18 16:04:26 UTC

repost: subqueries

Hello,

on 04.08. I have asked a question and have not got any
answer.  It is important to me, so I will try to reformulate.

Any help will be appreciated, for example a piece of
code or an explanation how to use the method
Criteria.addIn(String attributeName, Query subQuery)
for something that cannot be done using path expressions
(i.e., what other posters call "nested queries");

Here is what I am doing:

I have a model of the form

    [A] <--1--n--> [B] --1--1--> [C]

Moreover, B and C are abstract; 
C has a lot of subclasses and B has a few.
The concrete subclasses of B are mapped to one table,
those of C are mapped to distinct tables.

I can formulate org.apache.ojb.broker.query.Query qryB
to specify a particular set of B instances.

Now I would like to use the method 
  Criteria.addIn(String attributeName, Query subQuery)
(or something else) to formulate a query 

(i)  for all A instances for which there is a B-instance that
     matches qryB and has a reference to a specific C-instance z.

(ii) for all C instances for which there is a B-instance that
     matches qryB and is referenced by a specific A-instance x.

Of course, each of these queries should be translated into a 
single SQL statement.

I think at least (i) should be possible.  I have realized that
(ii) is very difficult because C has so many subclasses.

The above method is not covered by the OJB junit tests, and 
it seems to me that it is hardly useful. 

BTW: the OQL standard supports such queries.  
I think it is something like

(i) SELECT a from A WHERE a.b in SELECT b from B WHERE (qryB) and b.c = z

Can anybody help? 

Olli

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


Re: repost: subqueries

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi oliver

please see my post in dev-list '[vote] reference to a parent attribute 
in subquery'
this allows you to reference attributes of the enclosing query. please 
be aware that this is a _temporary_ solution, the prefix may change !

jakob

oliver.matz@ppi.de wrote:

>Hello,
>
>on 04.08. I have asked a question and have not got any
>answer.  It is important to me, so I will try to reformulate.
>
>Any help will be appreciated, for example a piece of
>code or an explanation how to use the method
>Criteria.addIn(String attributeName, Query subQuery)
>for something that cannot be done using path expressions
>(i.e., what other posters call "nested queries");
>
>Here is what I am doing:
>
>I have a model of the form
>
>    [A] <--1--n--> [B] --1--1--> [C]
>
>Moreover, B and C are abstract; 
>C has a lot of subclasses and B has a few.
>The concrete subclasses of B are mapped to one table,
>those of C are mapped to distinct tables.
>
>I can formulate org.apache.ojb.broker.query.Query qryB
>to specify a particular set of B instances.
>
>Now I would like to use the method 
>  Criteria.addIn(String attributeName, Query subQuery)
>(or something else) to formulate a query 
>
>(i)  for all A instances for which there is a B-instance that
>     matches qryB and has a reference to a specific C-instance z.
>
>(ii) for all C instances for which there is a B-instance that
>     matches qryB and is referenced by a specific A-instance x.
>
>Of course, each of these queries should be translated into a 
>single SQL statement.
>
>I think at least (i) should be possible.  I have realized that
>(ii) is very difficult because C has so many subclasses.
>
>The above method is not covered by the OJB junit tests, and 
>it seems to me that it is hardly useful. 
>
>BTW: the OQL standard supports such queries.  
>I think it is something like
>
>(i) SELECT a from A WHERE a.b in SELECT b from B WHERE (qryB) and b.c = z
>
>Can anybody help? 
>
>Olli
>
>---------------------------------------------------------------------
>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