IntelliJ open source
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Object Relational Mapping
 
RSS feed
 
New topic
Author

Multiple subclasses, one superclass in Hibernate.

Kristofer Hindersson
Greenhorn

Joined: Jan 19, 2010
Messages: 18

Hi, is this possible (using hibernate or-mapping):


...and how would I go about it?

/Regards Kris
Cameron Wallace McKenzie
author and cow tipper
Bartender

Joined: Aug 26, 2006
Messages: 4603

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








Author of Hibernate Made Easy, What is WebSphere???, Portlet Programming Made Easy and the SCJA Certification Guides
My Hibernate and JPA Tutorials * My Mock Java Certification Exams * My Online Java Tutorials * My CBT Portlet Tutorials.

Kristofer Hindersson
Greenhorn

Joined: Jan 19, 2010
Messages: 18

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

This message was edited 1 time. Last update was at by Cameron Wallace McKenzie

Cameron Wallace McKenzie
author and cow tipper
Bartender

Joined: Aug 26, 2006
Messages: 4603

Hmmmm......I'm going to have to think about that...

Author of Hibernate Made Easy, What is WebSphere???, Portlet Programming Made Easy and the SCJA Certification Guides
My Hibernate and JPA Tutorials * My Mock Java Certification Exams * My Online Java Tutorials * My CBT Portlet Tutorials.

 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Object Relational Mapping
 
RSS feed
 
New topic
IntelliJ open source

.