-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: 1 to 1 with inheritance in the same table
PostPosted: Wed Oct 04, 2006 8:28 pm 
Newbie

Joined: Wed Oct 04, 2006 8:11 pm
Posts: 6
Is there any possible way to map a 1 to 1 composition type of relationship where the child side of the relationship uses inheritance... and here is the catch... with everything in a single table?

In other words, class A depends on class B and class B has subtypes. A has a 1 to 1 relationship to B and owns B's lifecycle. All of this is maintained in one table.

Before, you say it is unreasonable to do it in a single table, from a data perspective, it really isn't. 1 to 1 relationships are often in a single table, and the inherited classes only add a few fields above and beyond the parent and can be nullable.

The two ways I thought to solve this were:

1) Make B a component within A, and use a class-per-hierarchy inheritance model on B. But this doesn't seem possible because I haven't seen a way to do inheritance with a component (value-type).

2) Make B and A both entity types that have a 1 to 1 relationship with each other. But, you can't make two entity types map to the same table (not that I know of anyways).

Is there a reasonable approach with Hibernate, or am I better off trying to do this with straight SQL?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.