-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-13586 : ClassCastException when using a single region name for both entity and query results #3006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…th entity and query results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably the best we can do with the API as-is, however I think this change misses the opportunity to change the API to prepare for a proper solution in 6.0. What we are seeing is that both a DomainDataRegion
and QueryResultsRegion
can be named the same, but that parts of the code still assume that generic access to a Region by name is possible. Basically, I'm not sure there is a time when generalized access to Region by name is needed. And a usage search backs that up. Use of this method from Hibernate itself fall into 2 categories:
- Calls from within the
CacheImplementor
itself - Calls from
Statistics
For CacheImplementor
the difference can be easily managed internally. For Statistics
, even though it calls #getRegion
it actually then handles the return specifically as either a DomainDataRegion
or QueryResultsRegion
.
So essentially, even though these regions share name they are still different things entirely and really ought to be split into 2 separate storage (Maps) and accessed specifically by type. Again, CacheImplementor
itself does currently expose some behavior that might need to look at both types but that is all internal - it can easily access both Maps for these calls.
So I would like to see this changed to be a bit more proactive in fixing the problem, which is partially API based (assuming we want to allow both types to use the same name). I'd suggest the following changes:
- Add a
CacheImplementor#getDomainDataRegion
method. Specific access to QueryCacheRegions already exist viaCacheImplementor#getDefaultQueryResultsCache
,CacheImplementor#getQueryResultsCache
andCacheImplementor#getQueryResultsCacheStrictly
; - Use these methods instead of
#getRegion
in places where we know we want one type or the other specifically - which, again, outside of theCacheImplementor
impls seems to be all of our uses; - Add
CacheImplementor#getDomainDataRegionNames
andCacheImplementor#getQueryCacheRegionNames
methods; - (?) deprecate
#getRegion
@sebersole, I purposely left SPI/API changes out of this fix, and was intending to follow this up with a separate issue to adress API/SPI changes. I'll look into your suggested changes though, and I'll include that in this jira if it doesn't look like it will break anything. |
Understandable about splitting changes into different commits. A PR of course can contain multiple commits but its fine if you wanted to hold off for that until later. However, IMO this change needs to be done. It won't break anything so long as we simply deprecate For now you could leave the internals as-is, although IMO this should be implemented through 2 separate Maps inside It you are not able to make these changes let me know and I will add it. |
@sebersole, I agree with what you wrote. The only exception is for I see that I'm in favor of deprecating both WDYT? |
@sebersole, while I'm at it, what do you think about deprecating |
…th entity and query results Make SPI changes to remove ambiguity when there is a DomainDataRegion and a QueryResultsRegion with the same name.
@sebersole, after looking more closely, I see that I've made the other SPI changes. I still need to add some tests. Please take a look and let me know how it looks to you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine to me.
WRT #evictRegion
... it can be deprecated so long as new methods such as #evictDataRegion
and #evictQueryRegion
are added. Of course it is fine to just leave it also if you prefer, so long as it clears the data from all matching regions by name regardless of the type of data stored there.
@sebersole, I thought about adding Currently, calling I realized there was still a little fuzziness to the new methods that I added. I figured it would be best to fix it now.
That makes it a bit clumsy for an application to use. I am changing The deprecated Going forward, I am clarifying the Javadoc so it is more obvious how the various methods deal with the default Does this make sense to you in principal? |
…th entity and query results Minor changes to added CacheImplementor methods
Added more test cases and made the changes proposed in previous comment. |
https://hibernate.atlassian.net/browse/HHH-13586