posted 12 years ago
I am trying to get a mapping to work correctly, it is persisting correctly but it is not selecting correctly. My class hierarchy is as follows:
Person
--AffiliatedPerson
----AffiliatedUser
------AffiliatedUserPlayer
--------AffiliatedUserPlayerCoach
------AffiliatedUserCoach
----AffiliatedPlayer
------AffiliatedPlayerCoach
----AffiliatedCoach
When I save the object regardless of what class I save, it is persisted to the database correctly, but when I select an object that is supposed to be, for example, AffiliatedPlayerCoach I instead get an instance of AffiliatedCoach. In the select query, I see the following which looks to me is Hibernate attempting to determine the class to instantiate:
By looking at this I can understand that the reason I am getting an instance of AffiliatedCoach instead of AffiliatedPlayerCoach, because the first "when" would be true and so it would return 8 which I assume is being used as the index of all sub-classes in the mapping. I guess my question is, is there any way to have Hibernate use a different case statement for this, or have it check all 8 cases rather than just 5? The way I would see a proper case statement for this situation is as follows:
Any help is greatly appreciated.