I tried what you suggested and I didn't get the results I want.  Let me
explain my problem a little more.

I have a Person class:

<class-descriptor class="com.wingate.us.db.Person" table="people">
  <field-descriptor name="ID" column="person_id" jdbc-type="BIGINT"
primarykey="true" autoincrement="true" />
  <field-descriptor name="firstName" column="firstname"
jdbc-type="VARCHAR"     nullable="false" />

...

  <collection-descriptor name="timeSheetDays" 
        element-class-ref="com.wingate.us.db.TimeSheetDay"
orderby="workDate"      sort="DESC" auto-retrieve="true">
        <inverse-foreignkey field-ref="personID"/>
  </collection-descriptor>
</class-descriptor>

And a TimeSheetDay class

<class-descriptor class="com.wingate.us.db.TimeSheetDay"
table="timeSheetDays">
        <field-descriptor name="ID" column="timeSheet_id"
jdbc-type="BIGINT"              primarykey="true" autoincrement="true"
/>
        <field-descriptor name="personID" column="person_id" 
                jdbc-type="BIGINT" />

...

    <field-descriptor name="workDate" column="work_date" 
        jdbc-type="TIMESTAMP" nullable="false"/>

    <reference-descriptor name="person" 
                class-ref="com.wingate.us.db.Person" >
      <foreignkey field-ref="personID"/>
    </reference-descriptor>
...

  </class-descriptor>


This should define a 1:M relationship between Person and TimeSheetDays
and a 1:1 relationship between TimeSheetDays and Person.

If I do a query like:

Criteria crit = new Criteria();
crit.addBetween("timeSheetDays.workDate", startDate, endDate);

Query q = QueryFactory.newQuery(Person.class, crit, true);
Collection results = _pb.getCollectionByQuery(q);

I get back a list of Person objects who have TimeSheetDays between the
startDate and endDate.  That is ok, but the TimeSheetDays collection
(inside of each Person object) contains all TimeSheetDays for that
Person.  What I want is for TimeSheetDays collection (inside of the
Person object) to contain only those TimeSheetDay objects that fall
between the startDate and endDate.

If I execute a query like (which is what I think you suggested):

Criteria crit = new Criteria();
crit.addBetween("workDate", startDate, endDate);

Query q = QueryFactory.newQuery(TimeSheetDay.class, crit, true);
Collection results = _pb.getCollectionByQuery(q);

I get back a list of TimeSheetDay ojbects that fall between the
startDate and endDate.  But what I want is the inverse of this (as
explained above).

Does that make sense?

Like I mentioned, I can see how I could do this "manually":  Query for
the list of people and then for each person do another query for the
right TimeSheetDays collection and then manually set that collection in
each person.  But I would think OJB could handle this for me if I could
just set up the query correctly.

Is there a slick way to handle this?

-Jason
 
 

> -----Original Message-----
> From: Robert S. Sfeir [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, February 18, 2003 7:01 PM
> To: OJB Users List
> Subject: Re: 1:M querys constraints
> 
> relate the day class to people, then do the search on the day class
> date range, and set auto-retrieve=true it should populate everything
in
> one Collection.
> 
> 
> On Tuesday, Feb 18, 2003, at 19:11 US/Eastern, Jason Hale wrote:
> 
> > I am looking for the best way to handle the following situation:
> >
> > Let's say I have a 1:M relationship between a person and day class.
I
> > would like to execute a query that would give me back all the people
> > but
> > constraint the list of day objects for each person.  Something like,
> > "give me all people, but only populate my days collection with days
> > between 2/1/2003 and 2/15/2003"
> >
> > I can get this to work by retrieving all the people and then for
each
> > person execute a query that returns my constrained day collection
and
> > then manually setting that collection on the person object.  But
this
> > does not seem optimal.
> >
> > Any suggestions?
> >
> > -Jason
> >
> >
> >
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> R
> 
> --
> Robert S. Sfeir
> Senior Java Engineer
> National Institutes of Health
> Center for Information Technology
> Department of Enterprise Custom Applications
> [EMAIL PROTECTED]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]




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

Reply via email to