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?
|