[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-271) subclass lazy fetching returns wrong object

Fred Arters (JIRA) noreply at atlassian.com
Wed Oct 19 15:25:19 EDT 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44089#comment-44089 ] 

Fred Arters commented on HHH-271:
---------------------------------

6 years later and I ran into this same situation.  I found that the lazy fetch was causing the problem from another ticket, regarding using discriminator fields with InheritanceType=JOINED.  The answer to that rejected ticket was that hibernate was elegant enough not to need discriminator fields for joined inheritance.  Someone brought up that if hibernate supported discriminator fields in these cases, lazy fetches for inherited classes would return the correct sub-type.  Seems like the answer to that ticket and the answer to this one are in conflict.  Additionally, I would, and did not, expect that changing the fetch type to lazy would return a different result than eager fetch.  In my case an eager fetch is not going to hurt me so I will do that.  

> subclass lazy fetching returns wrong object
> -------------------------------------------
>
>                 Key: HHH-271
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-271
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.0 rc 1
>            Reporter: Michael Kopp
>
> I have a table per hierarchy mapping with discriminators. Another class has a many-to-one relation to the root class. When my program accesses the getter for this many-to-one relation, it should get a subclass of the root class. What it gets is a CGLIB proxy of the root class (com.j2fe.workflow.definition.Node$$EnhancerByCGLIB$$63e262e8). 
> When I turn of lazy fetching on the root class (Node) everything works as expected.
> I have another class with a one-to-many collection of the root class. If I iterate through this before accessing the many-to-one getter, It also works correctly.
> One important note at last, the discriminator is set to force.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list