• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple subclasses, one superclass in Hibernate.

 
Kristofer Hindersson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, is this possible (using hibernate or-mapping):


...and how would I go about it?

/Regards Kris
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did this scenario come from?

I'm curious about the DTYPE field in the two tables. It would appear that this has already been mapped, as DTYPE is the standard attribute used to distinguish between object types that share an inheritance hierarchy. Curious, as I usually see that with a one-table mapping strategy, but here you have two tables. For example, here is an inheritance hierarchy, and then the single table that is created for it:





Here's a tutorial on mapping inheritance:

Mapping Inheritance with Hibernate

-Cameron McKenzie







 
Kristofer Hindersson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thanks for another quick reply. The scenario I've depicted is one I made up to illustrate the hypothetical situation of a non-linear inheritance. I used your example from Hibernate made easy as a base. The problem is that the book only deals with the linear case of inheritance (Ancestor <- Parent <- Child). Let's say that I have a Person-class which holds attributes like firstname and lastname and then want to create the two classes Administrator (with a password attribute) and User, both of which extends Person. I don't want the administrators password to be stored in the same table as that of the user and I don't want use separate tables for Person, Adminstrator and User etc. Would hibernate support using the single table strategy, only separately for Person<-Administrator and Person<-User? I hope I'm not confusing the issue..

Regarding the DTYPEs I just put them there thinking it would be how it would work out (it's probably wrong though?)

/Kris
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmmm......I'm going to have to think about that...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic