[JIRA] (HHH-16254) Session load by pk returns proxy in association when using "batch fetch size", "cache", "fetch mode select", "single table inheritance"
by Jones (JIRA)
Jones ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *commented* on HHH-16254 ( https://hibernate.atlassian.net/browse/HHH-16254?atlOrigin=eyJpIjoiNWQ5YT... )
Re: Session load by pk returns proxy in association when using "batch fetch size", "cache", "fetch mode select", "single table inheritance" ( https://hibernate.atlassian.net/browse/HHH-16254?atlOrigin=eyJpIjoiNWQ5YT... )
Yes, of course.
The issue is that we have a huge 10+ years application with more than 300 entities and unfortunately more than 100 entities are polymorphic entities, some with a few hierarchy levels (single table with column discriminator).
Almost all of these polymorphic entities are annotated with @Proxy(lazy=false) , except this one case that made me report this issue.
Because this one wasn’t annotated, and that relationship was returning a proxied entity, we started getting ClassCastException in several places in our code.
Adding @Proxy(lazy=false) solves this issue, but I’m aware this is not a good solution and also that @Proxy just got deprecated.
When reporting this issue I wasn’t aware all the reasoning why we were using this annotation, but now that’s completely clear for me, and it was a lazy workaround to avoid `ClassCastException` and continue to use type cast and instanceof statements for such entities. Since I see that @Proxy probably will get no replacement ( [ HHH-15772 ( https://hibernate.atlassian.net/browse/HHH-15772 ) Closed deprecate @Target, @Proxy, @Polymorphism - Hibernate JIRA (atlassian.net)|https://hibernate.atlassian.net/browse/HHH-15772] ), I’m moving to a definitive solution:
* Remove all @Proxy(lazy = false) from our entities
* Replace all casts and instanceof for those entities in our codebase (a huge search/replace)
* Ensure that no casts or instanceof are used anymore for those entities (I’m able to achieve this using TNG/ArchUnit: A Java architecture test library, to specify and assert architecture rules in plain Java (github.com) ( https://github.com/TNG/ArchUnit ) , where I even created a PR to support type casts - support type cast detection by ratoaq2 · Pull Request #1081 · TNG/ArchUnit (github.com) ( https://github.com/TNG/ArchUnit/pull/1081 ) )
So, in summary I wasn’t sure if this specific change in behaviour in hibernate was intended or not, therefore I created this issue with a test case. Now with more clarity, I understand this was intended and I just need to handle its consequence and probably this issue should be closed.
Thanks
( https://hibernate.atlassian.net/browse/HHH-16254#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16254#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100217- sha1:2199b34 )
3 years, 1 month