• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate nested joined-subclass

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don Blodgett
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I managed to figure out a solution to this problem, not one that I particularly like, but it works. I created a sql-query that is basically the same as the query that Hibernate creates, but I replaced the case statement with my own case statement and eliminated a few of the redundant joins and it is working now.
 
reply
    Bookmark Topic Watch Topic
  • New Topic