> One side of prefetching is saving us uneeded queries, when we know upfront 
> which related objects we need in addition to the main query result. This is 
> the angle shown in the docs where prefetching is presented as a performance 
> optimization tool.

yes, thats ok.

> But there is another side of it, which is just as important. It is about 
> fine-grained control of refreshing parts of the object graph already in 
> memory. When a query is run, Cayenne can't automatically refresh all objects 
> directly or indirectly connected to the query result objects, as it would 
> cause a massive fetch. With prefetching Cayenne knows how much of the object 
> graph we want to refresh.

Makes sense.

> So I don't find the result all that surprising. (Although if things happen in 
> the same JVM I am still surprised the relationship isn't refreshed via 
> Cayenne cross-context event mechanism. This could be a race condition 
> actually, as events are delivered asynchronously)

Actually there were no additional events but only two http requests
with 10 seconds between them. No additional ajax. So I can expect two
different contexts, because every request gets its own context -
right?

Can we assume I selected "firstObject" without any prefetching and did
then something like:
firstObject.getSecond().getThird();

I get the second object. But calling second.getThird(); returns null.
Why? Isn't it so that at this place getThird should cause a SQL query?
If this is not the case it still does not explain why it worked from
time to time.

I am really interested in what caused this problem. Thanks guys for
all your patience with me.

Cheers,
Christian


> Andrus
>
>
> On Sep 16, 2011, at 10:01 PM, Christian Grobmeier wrote:
>
>> I have not had duplication issues so far. But I will double check now.
>> I added this code b/c of the problems with the null values, so it isnt
>> the root cause for my problem.
>> At the moment it still looks good. It seems that the prefetch helped.
>> I am very puzzled about it :-)
>>
>> On Fri, Sep 16, 2011 at 8:30 PM, Michael Gentry <[email protected]> 
>> wrote:
>>> I seem to recall doing a setX() followed by an addToY() causes a
>>> duplicate Y to be added.  I'd have to double check this, but that is
>>> my recollection.
>>>
>>> On Fri, Sep 16, 2011 at 2:19 PM, Andrus Adamchik <[email protected]> 
>>> wrote:
>>>>> but may cause duplication issues for addToY().
>>>>
>>>> I hope it doesn't. But since I am trained to just set the rel in one 
>>>> direction, I may not be aware of the issue.
>>>>
>>>>
>>>> On Sep 16, 2011, at 9:12 PM, Mike Kienenberger wrote:
>>>>
>>>>> On Fri, Sep 16, 2011 at 4:22 AM, Christian Grobmeier
>>>>> <[email protected]> wrote:
>>>>>> userRoles.setUser(user);
>>>>>> userRoles.setRole(role);
>>>>>> user.addToUserRoles(userRoles);
>>>>>> role.addToRolesToJoin(userRoles);
>>>>>
>>>>> Again, unless, you've specifically made both relationships
>>>>> unidirectional (the default is bidirectional), you are actually
>>>>> setting both sides of the relationship twice.   Not an issue for a
>>>>> SetX(), but may cause duplication issues for addToY().
>>>>>
>>>>
>>>>
>>>
>>
>>
>>
>> --
>> http://www.grobmeier.de
>>
>
>



-- 
http://www.grobmeier.de

Reply via email to