aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate nested joined-subclass Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate nested joined-subclass" Watch "Hibernate nested joined-subclass" New topic
Author

Hibernate nested joined-subclass

Don Blodgett
Ranch Hand

Joined: Jan 09, 2006
Posts: 61
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

Joined: Jan 09, 2006
Posts: 61
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate nested joined-subclass
 
Similar Threads
joined-subclass problem
Hibernate. Nested transactions. Lock
Hibernate join and key tag
Hibernate & Date
Clarification needed in usuage of Example criteria.