Is it possible to configure Hibernate to store a component class in a separate table?
Take the following example:
<class name="test.ClassA">
<property name="propA"/>
<component name="componentProp" class="test.ClassB">
<property name="propB"/>
</component>
</class>
This maps to a table called MyClass
with two columns propA
and propB
. What I want is to map the properties of the component to a table called ClassB
.
What I don't want to do is configure ClassB
as an entity in itself (it has no meaningful identity outside of ClassA
), so that rules out a normal association. Also, I cannot modify the object model (it's generated code), so I can't introduce an ID property to ClassB
.
This seems to be a gap in Hibernate's functionality - the <component> mapping performs "multiple-classes-to-one-table", and <join> does "one-class-to-multiple-tables", but oddly there's no apparent way of doing "multiple-classes-to-multiple-tables", without resorting to entity associations.
My rationale for wanting this is that I want my DB schema to resemble the object model as closely as is practical, and that includes separate tables for the ClassB
component. I understand that this wouldn't scale - you couldn't do nested components, for example, but this isn't a problem in this particular situation.