My favorites | Sign in
Project Home Downloads Issues Source
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 686: Nested queries should use namespace cache
1 person starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  gus4...@gmail.com
Closed:  Oct 2012


Sign in to add a comment
 
Project Member Reported by gus4...@gmail.com, Oct 4, 2012
What version of the MyBatis are you using?
3.1.1 and latest trunk

Please describe the problem.  Unit tests are best!
If I run AuthorMapper.selectAuthor(101) with caching on, then that query will be put in the AuthorMapper namespace cache. All future calls to AuthorMapper.selectAuthor(101) will return a cached version. However, if I retrieve a Blog which has an association via a nestedQueryId/select with Author 101 then the namespace cache is not referenced at all and a separate SELECT is issued to the database. I would expect that all calls to AuthorMapper.selectAuthor(101) either directly or indirectly via a nested select should return the cached version.

What is the expected output? What do you see instead?
I expect to see the cached Author returned, but instead a select statement is run against the database and a new Author is returned

Can you provide stack trace, logs, error messages that are displayed?
I have provided a patch for the code (generated against latest trunk), and am working on adding appropriate tests which I will upload later

Please provide any additional information below.
Use_cache_for_nested_query.patch
11.9 KB   View   Download
Oct 8, 2012
Project Member #1 gus4...@gmail.com
Attaching patch with test
Use_cache_for_nested_query-tests.patch
14.2 KB   View   Download
Oct 23, 2012
Project Member #3 gus4...@gmail.com
(No comment was entered for this change.)
Owner: gus4...@gmail.com
Oct 24, 2012
Project Member #4 gus4...@gmail.com
Fixed in r5445
Status: Fixed
Mar 12, 2013
#6 mof...@gmail.com
Hi Guys - can we get this implemented for Lazy Loading as well?  The Lazy Load does not work in the same fashion and doesn't pick up the benefits of the cache, although the result does get added to the top level object if it is cached.  Additionally, it is important that the cache be re-examined on subsequent get operations, since the sub-queries could be in different namespaces, and their caches may have been cleared due to a write operation, while the holding object might still be cached in it's own namespace.

E.G.

- Response Status getStatus() - assume cached now / ResponseStatus namespace cache
- Later, Find Response Object - ResponseMapper namespace cache
--> response.getStatus() -   // lazy loaded via query // returns 123, no cache?
Later on -- updateStatus(456) - clears ResponseStatus cache
After that -- Response Object.getStatus() // still returns 123

So there are two issues:
1.  getStatus() lazy loaded does not use the cache
2.  subsequent calls to getStatus() do not check the cache to see if the value should be requeried.

Thanks,

Mike
Sign in to add a comment

Powered by Google Project Hosting