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.




Hi Dennis.

you can use too ReportQueryByCriteria.

for example:

make criteria:
Crit criterio = new Criteria();
crit.addEqualTo("area_id", new Integer(2));

Create the Query:
ReportQueryByCriteria query = new ReportQueryByCriteria(Table1.class, crit);

then you need to tell what fields you want in the result:
query.setAttributes(new String[] { "fieldName", "pathToField.fieldName", "pathToField.fieldName"});

later you can obtain a collection of object[] where each item of the array are each field, each item have a datatype equal to each field:
Iterator iter = broker.getReportQueryIteratorByQuery(query)

Then you can access to rows of the result.

Cheers.
Carlos Chávez.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to