db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter S. Hamlen" <pham...@mail.com>
Subject Re: problem retrieving foreign collection
Date Wed, 15 Jan 2003 20:23:16 GMT
The "getProjekts" behavior is slightly complicated.  If you look at the
generated code, you'll see that it does a form of "lazy" loading. 
Essentially, it only loads the projects if they haven't been loaded
already.

So you could get your behavior in the following scenario:
1)  Create/load a user from the database.
2)  Create a criteria that will not return any projekts 
3)  Call getProjekts(funkyCriteria) - this will return 0 from the
database because no projekts meeet the criteria.
4)  Call getProjekts() - this will STILL return 0 because projekts have
already been loaded.

You could also get your behavior by the following:
1)  Create/load a user from the database.
2)  Call getProjekts() - this will return 0 from the database because no
records have been added yet.
3)  Create a projekt for the user by setting the UserId for the projekt
and save it to the database.
4)  Call get Projekts() - it will still return 0 because THE PROJEKTS
HAVE ALREADY BEEN LOADED.
5)  The workaround for this problem is to call user.addProjekt() BEFORE
you save the projekt to the database.  addProjekt will add the new
projekt to the collection.

Hope this helps
-Peter

On Tue, 2003-01-14 at 15:19, Marc Lustig wrote:
> Hi,
> 
> I have a strange behaviour here:
> There is one Projekt related to my user.
> 
> user.getProjekts(); returns zero Projekts (WRONG)
> 
> When I replace the line with
> user.getProjekts(new Criteria());
> one Projekt is returned (correct).
> 
> I really can't follow what is going on here, as method getProjekts() simply
> creates an empty Criteria and passes to getProjekts(Criteria c):
> 
>     public List getProjekts() throws TorqueException
>     {
>         if (collProjekts == null)
>         {
>             collProjekts = getProjekts(new Criteria(10));
>         }
>         return collProjekts;
>     }
> 
> What's that?
> 
> Marc
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:turbine-torque-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:turbine-torque-user-help@jakarta.apache.org>
> 



Mime
View raw message