Association retrieves over database retrieves

0
I've seen a lot of discussions about Association retrieves vs Database retrieves and it looks like in general people thinks that Association retrieves are better for performance because they can possibly retrieve directly from local memory. I'm however not fully convinced of this. More often than not retrieved entities will not be in local memory, so that association retrieve will still call on the database. Plus there are potential security risks when working with the 'dirty' state of an object.    what are your views on this topic?    
asked
1 answers
0

I agree that the transactional state of an object can affect the result of an by association retrieve vs a database retrieve.

But I dont see the security risk, because when you dont have access rights on the referenced object, the return will be empty incase of a dirty set association. If it would happen, your access rights aren't correct.

 

Next to that I agree you should always make the right choice and there are many cases where by association could be quicker, but from DB is correct

 

One example can be found in the rapid developer course, when calculating the NrOfRegistrations.

 

First retrieve is retrieve of the associated TrainingEvent by association. This is correct and the quickest, as it happens after the commit of the context object registration. If from database would return something different than by association,  you have big problems. (Not being the retrieve itself)

 

While the second one is from database. Retrieving all registrations of the just retrieved TrainingEvent. When you would retrieve them by association. You could retrieve uncommitted registrations and thus the count would be wrong. And also, dB retrieve + aggregate will be optimised to count/sum/... Select instead of a retrieve

answered