Hi again Krupa,

maybe I didn't understand what you were asking for.

As you can see in the link I gave you, Report queries are used to retrieve
row data, not 'real' business objects.
So if you want to retrieve row data holding all the fields of
ActualObject,  ReportQueryByCriteria is suitable for you, while if you want
to retrieve the business object (the value object) ActualObject,
ReportQueryByCriteria is not suitable for you.

In the first case


Criteria crit = new Criteria();

crit.addEqualTo("fld3", new Integer(1));

ReportQueryByCriteria q =
QueryFactory.newReportQuery(LinkObject.class, crit);
q.setAttributes(new String[] {
"ActualObject.fld1","ActualObject.fld2",....., "ActualObject.fldN" });
Iterator iter = broker.getReportQueryIteratorByQuery(q);

If you need to retrieve a collection of the business object
ActualObject, in the way you have configured your repository.xml, I
don't know if it is possible retrieve directly. I think that it isn't,
but if I'm in a mistake please that someone advise me.

Anyway in such cases I use a small framework of mine called Mandragora
 http://mandragora.sourceforge.net/

that you can see as an help to deal with Ojb.



In your case I'd do the following what I do is the following:



ry {
    BD bd = 
ServiceLocator.getInstance().getManagerBD("BDFactoryDefaultClass","StandardBDDefaultClass");

    Collection linkObjects=
bd.findCollectionByLogicCondition(LinkObject.class,new
LogicSqlCondition("fld3","==",new Integer(1)));

 bd.retrieveReferenceInCollection(linkObjects, "ActualObject"); /*
this is not necesary if you put autoretriece="true" in the reference*/

 Collection ActualObjects =
Utils.selectFieldFromCollection(linkObjects, "ActualObject");
    } catch (ApplicationException e) {
    //manage the exception

}

Once you got the bd, the first sentence, just builds the Ojb criteria,
the broker, and executes it as if it was

Criteria criteria = new Criteria();

crit.addEqualTo("fld3", new Integer(1));

QueryByCriteria query = QueryFactory.newQuery(LinkObject.class, criteria);

Collection linkObjects = broker.getCollectionByQuery(query);

The second sentence just loads the ActualObject for each linkObject.

And the third iterates over the collection of linkObjects, it  gets
for each one his actualObject and adds it to the collection
ActualObjects that is returned.






I hope this help

Alessandro



On 11/14/07, k jee <[EMAIL PROTECTED]> wrote:
>
> Thank you Alessandro Colantoni.
>
> I looked in to ReportQueryByCriteria
> If I have a repository.xml as below, using report query how can I return
> only the ActualObject
>
> <class-descriptor
> class="package1.LinkObject"
> table="Table1">
>
> <field-descriptor
> name="fld1"
> column="FLD1"
> jdbc-type="INTEGER"
> primarykey="true"
> />
>
> <field-descriptor
> name="fld2"
> column="FLD2"
> jdbc-type="INTEGER"
> primarykey="true"
> />
> <reference-descriptor
> name="ActualObject"
> class-ref="Package1.ActualObject"
> >
> <foreignkey field-ref="fld1"/>
> <foreignkey field-ref="fld2"/>
> </reference-descriptor>
> </class-descriptor>
>
> When I use the reportQueryByCriteria how I can return only the
> ActualObject in the collection.
>
> Thanks,
> Krupa
>
>
> Alessandro Colantoni <[EMAIL PROTECTED]> wrote:
> Hi Krupa,
>
> If you want to have returned fields of more than one table, you have to
> use
> the
>
> ReportQueryByCriteria
>
> have a look here:
> http://db.apache.org/ojb/docu/guides/query.html#Report+Queries
>
> To specify the joins the only way I use is to specify the relationship in
> the repository.xml.
>
> Anyway in the class ReportQueryByCriteria there is a method *
> setJoinAttributes*
> (java.lang.String[] joinAttributes)
>
> I Hope this helps
>
>
> On 11/13/07, k jee wrote:
> >
> > Hi All,
> >
> > How can I write the following query in OJB?
> >
> > SELECT * FROM Table1 AS t1JOIN table2 AS t2 ON t1.fld1 = t2.fld1 AND
> > t1.fld2= t2.fld2 AND t1.fld3= 1
> >
> > Thanks,
> > Krupa
> >
> >
> > ---------------------------------
> > Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See
> > how.
>
>
>
> ---------------------------------
> Get easy, one-click access to your favorites.  Make Yahoo! your homepage.

Reply via email to