Proxy Narrowing (HHH-9071) breaks polymorphic query

Description

As originally discussed here:
https://forum.hibernate.org/viewtopic.php?f=1&t=1041975

I'm encountering an issue with changes made in 4.3.5.Final (and 4.2.12.Final) via https://hibernate.atlassian.net/browse/HHH-9071#icft=HHH-9071 related to Proxy narrowing. A test case is attached which demonstrates the following behavior:

Given a model where:
#a class hierarchy where User is a parent class of AdvancedUser
#a class UserConfig with a many-to-one to User

When executing a query for a specific UserConfig, the getUser() returns a proxy of User.class. However, immediately executing a second (polymorphic) query for that same user directly, fails to return the AdvancedUser instance.

This works fine in 4.3.4.Final (and 4.2.11.Final). That is, this same code returns the proper AdvancedUser instance from the second query.

Activity

Show:

Steve Ebersole February 24, 2021 at 4:39 PM

Casting is not polymorphism. Closing this

Christian Beikov June 30, 2020 at 8:17 AM

I guess a workaround could be to join fetch the association or to load the object by id after removing the proxy from the persistence context with detach.

Raf Fareen June 29, 2020 at 7:34 PM

Does this issue only affect versions 4.3.5, 4.2.12, and 5.2.4 as indicated in the ticket?

I am in the process of upgrading a 4.2.3.Final hibernate to either 4.2.21.Final or 4.3.11.Final or 5.3.X.Finaland we do have such use cases in our codebase.

Since this is a WIP issue with no ETA, is there a workaround fix for this issue?

Christian Beikov May 16, 2018 at 6:05 PM

Sorry but we didn't agree on anything specific yet, but even then, this is not something that is going to be done anytime soon. I'll schedule it for 6.0 but can't make any promises.

Josh Landin May 15, 2018 at 9:20 PM
Edited

@Christian Beikov Have you received answers to your questions? What else is needed to get a fix in?

Fixed

Details

Assignee

Reporter

Fix versions

Affects versions

Priority

Created November 28, 2016 at 11:00 PM
Updated February 24, 2021 at 4:39 PM
Resolved February 24, 2021 at 4:39 PM

Flag notifications