Hello,<br>
<br>
I am trying to figure out how hibernate second level caching works with
query cache turned off. I debugged through the source and have a
primitive idea of the flow which I have listed below. I am not able to
figure out at which point in the code flow objects are being fetched
from the second level cache. <br>
<br>
Below I have listed the flow for a HQL query execution with Object caching turned on and query caching turned off:<br>
<br>
HQL QueryLoader list method is called which calls the Loader List method.<br>
<br>
The Loader List method checks as to whether the Query is cacheable or
not (In my case this is false as I have disabled query caching) and
calls listIgnoreQuerCache.<br>
<br>
listIgnoreQueryCache calls getResultList passing result of doList and result trasformers as arguments.<br>
<br>
Inside doList doQueryAndInitializeNonLazyColl<div id="1fy7" class="ArwC7c ckChnd">ections is called.<br>
<br>
doQueryAndInitializeNonLazyCollections calls doQuery.<br>
<br>
Inside doQuery the resultSet is got and the result set is dissected to
get the values from the result set. For this getRowFromResultSet is
called.<br>
<br>
The first line of getRowFromResultSet retrieves the EntityPersister object for the applicable entity. <br>
<br>
Here the EntityKey is retrieved and the Object corresponding to the row is got. To do this getRow method is called.<br>
<br>
getRow checks as to whether the Entity is already in the Session cache
or not. If not gets the Entity using instanceNotYetLoaded.<br>
Inside instanceNotYetLoaded the Class to which the Entity should be mapped to is got.<br>
<br><b>
At this point should the code not check as to whether the object is
already in the cache or not and if present get the object from the
cache as the cache stores objects in their dehydrated form and this is what we are doing here.<br></b>
<br>
At this point a new Object corresponding to the Entity is instantiated
with the Object having only the Primary Key with no other values.<br>
Now the object is hydrated.(My guess is we are trying to get the other filed values)<br><br>Now loadFromResultSet is called.<br>
Here a Loadable object corresponding to the entity is got.<br>
TwoPhaseLoad.addUninitializedEntity method is called. Here a new Entity Object is created and added to an Internal event cache.<br>
<br>After this the row names are got and the values corresponding to the
rows are extracted. This is termed hydrating. Anyways once this is done
we have<br>
an array of column values.After this all associations are resolved and
then postHydrate is called. Here once again the Entity is added to an
event source internal cache(Am not sure<br>
as to whether we are adding it as a new entry or manipulating the old entry. My guess is we are manipulating the old entry). <br>
<br>
At this point the result set is done processing. I guess at this point
one stage of processing is done (We have an Entity Object and the field
values in <br>
hydrated array state) and now we move over to the next stage.<br>
<br>
In this stage we get the Entity Object from the cache populated in the
previous stage and try to fill the Object with values got from the
hydrated array.(Should the cache be <br>
checked at this point?)<br>
<br>
As the last part of the second stage I see code to populate the secondary cache with the created objects.<br>
<br><b>
My biggest problem is I am not able to see any code being called in the
whole cycle that fetches the Objects from the cache. I see lots of
second level cache related code in <br>
DefaultLoadEventListener class but I do not see any of this being called.<br></b>
<br>
Can someone please guide and correct me wherever my understanding is incorrect?<br><font color="#888888">
</font></div>-- <br>Cheers,<br>Abhi