Hibernate store loadXWikiDoc(XWikiDocument doc, XWikiContext context) implementation does not take into account doc wiki and search in the current database. This always been like this and a known behavior.
The problem is that XWikiCacheStore#loadXWikiDoc does not take into account the context when calculating the document cache key and might end up associating the document currentwiki:Space.Page with the key docwiki:Space.Page.
We don't have much issue with that because XWiki#getDocument is taking care of updating the context based on the document wiki but it's still dangerous.
There is several possibility:
- stop searching in the context wiki and search in the document wiki instead
- calculate the new key based on the found instance
1 is probably what makes more sense but since it's a behavior change it's probably a discussion for another time and another API probably, one not passing a context to be explicit.