You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@ws.apache.org by Dennis Riedel <de...@web.de> on 2005/08/08 10:10:30 UTC

Query on multiple tables

Hello
I am new to OJB and asking myself, how to query multiple tables using 
the persistenceBroker.
I cannot follow the example given on the OJB Query Page, I don`t 
understand it.

I have three tables and all contain one column 'area_id'. I want to find 
all entries in all tables containing a specific area_id, e.g. '2'.
So I think joining them would be the idea.

When I expect one resulting object of that query (there can be only one 
result, that is a fact), of which type will this be?
I workd with DAO Classes to recieve a special object or a collection of 
special objects.

But how is it, when I query on three tables, representing three 
different objects? Do I need a wrapper? Should these three objects 
implement the same interface to 'encapsulate' or 'wrap' the resulting 
object?

With my actual knowledge I would query each table with its DAO but that 
would be three queries to get the result.
I want one query.

Thanks for any support on querying multiple tables.

Re: Query on multiple tables

Posted by Tino Wildenhain <ti...@wildenhain.de>.
Am Montag, den 08.08.2005, 10:10 +0200 schrieb Dennis Riedel:
> Hello
> I am new to OJB and asking myself, how to query multiple tables using 
> the persistenceBroker.
> I cannot follow the example given on the OJB Query Page, I don`t 
> understand it.
> 
> I have three tables and all contain one column 'area_id'. I want to find 
> all entries in all tables containing a specific area_id, e.g. '2'.
> So I think joining them would be the idea.
> 
> When I expect one resulting object of that query (there can be only one 
> result, that is a fact), of which type will this be?
> I workd with DAO Classes to recieve a special object or a collection of 
> special objects.
> 
> But how is it, when I query on three tables, representing three 
> different objects? Do I need a wrapper? Should these three objects 
> implement the same interface to 'encapsulate' or 'wrap' the resulting 
> object?
> 
> With my actual knowledge I would query each table with its DAO but that 
> would be three queries to get the result.
> I want one query.

Yes, wrong list :-)
But what you want is usually done with UNION

SELECT a,b FROM table1 WHERE ...
UNION
SELECT a,b FROM table2 WHERE ...


There is UNION ALL, EXCEPT, INTERSECT... see your favourite
SQL manual for details
-- 
Tino Wildenhain <ti...@wildenhain.de>


Re: Query on multiple tables

Posted by Dennis Riedel <de...@web.de>.
SORRY!
Wrong maillist. Copied the wrong address.


Dennis Riedel wrote:

> Hello
> I am new to OJB and asking myself, how to query multiple tables using 
> the persistenceBroker.
> I cannot follow the example given on the OJB Query Page, I don`t 
> understand it.
>
> I have three tables and all contain one column 'area_id'. I want to 
> find all entries in all tables containing a specific area_id, e.g. '2'.
> So I think joining them would be the idea.
>
> When I expect one resulting object of that query (there can be only 
> one result, that is a fact), of which type will this be?
> I workd with DAO Classes to recieve a special object or a collection 
> of special objects.
>
> But how is it, when I query on three tables, representing three 
> different objects? Do I need a wrapper? Should these three objects 
> implement the same interface to 'encapsulate' or 'wrap' the resulting 
> object?
>
> With my actual knowledge I would query each table with its DAO but 
> that would be three queries to get the result.
> I want one query.
>
> Thanks for any support on querying multiple tables.
>