Interesting.  This is a situation I'd prefer never occur anyway.  IMO,
ToManyList should work like a Set with a defined iteration order.  This
wouldn't necessarily preclude duplicates because the uniqueness would be
based on the key.

The trade-off is the overhead of managing those semantics.  Although, I've
done it locally (subclassed CayenneDataObject) and haven't noticed a severe
performance hit.

I believe you'll be able to work directly with Sets in Cayenne 3.0.  This
would probably be a better approach for you, providing that insertion order
does not matter much.

-- 
Kevin Menard
Servprise International, Inc.
Remote reboot & power control for network equipment
www.servprise.com              +1 508.892.3823 x308


On 11/20/07 3:48 AM, "Alexander Lamb (dev)" <[EMAIL PROTECTED]> wrote:

> Hello,
> 
> In my code example, there is actually a bug.
> Indeed, if I do:
> 
>>>>     List<Role> roles = getObjectContext().performQuery(query);
>>>>     ToManyList tml = new ToManyList(this,"roles");
>>>>     tml.addAll(roles);
>>>>     writePropertyDirectly("roles",tml);
>>> 
> 
> 
> I will end up with twice the number of roles... Indeed, doing "addAll"
> will first fire the to-many which was just created before adding the
> objects...
> The only way to avoid that initial fetch is to do:
> 
> tml.setObjectList(roles)
> 
> then continue with the writePropertyDirectly.
> 
> Alex
> 
> 
> Le 15 nov. 07 à 10:45, Alexander Lamb (dev) a écrit :
> 
>> 
>> 
>>> The code below should work. Another way is to use multi-step
>>> prefetching on a root of to-many relationship.
>> 
>> Well, that's a good news so we shall probably implement my piece of
>> code for most relationships. However, I am afraid I didn't
>> understand your second sentence:-(
>>> 
>>> 
>>>> Now, it would still be cool if we could have batch faulting for
>>>> the odd places where we didn't set up the prefetching.
>>> 
>>> While I used batch faulting in webobjects days and found it quite
>>> useful, I could never understand how to make it work predictably
>>> (i.e. fault the objects that I care about). I wouldn't object
>>> though to somebody (or even myself) implementing it at the
>>> framework level if whoever that is could explain me the algorithm
>>> used to select which objects to fault. IIRC EOF builds internal
>>> "fault chains". Wonder how much overhead this would incur in Cayenne.
>> I don't think there is a particular order in which the faults are
>> fired. Actually, it is not a problem since gradually in a few
>> queries, all outstanding faults will be fired. My guess is that upon
>> firing the first fault of a to-one registered to batch fault, you
>> simply (ok, not that simple:-) look at all entities of same class in
>> the DataContext and take the first X to be fired at random. X being
>> the size of the batch. Of course, it some how means if there is a to-
>> one which needs to be batch faulted it has to be flagged somewhere
>> so you quickly know which objects to take into account.
>>> 
>>> BTW relationship prefetching policies can be specified per JPA spec
>>> (and hence will be implemented in Cayenne). However my
>>> understanding is that JPA specifies a different kind of prefetch -
>>> which attributes/relationships to resolve eagerly when an object is
>>> fetched.
>> 
>> I am afraid I don't know anything about JPA, but it probably means
>> in the future some kind of interface in the modeler to be able to
>> specify those prefetches?
>> 
>> Thanks!
>> 
>> Alex

Reply via email to