Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Hibernate nested joined-subclass

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic