Note that there are some explanatory texts on larger screens.

plurals
  1. POMapping hibernate components to a separate table
    primarykey
    data
    text
    <p>Is it possible to configure Hibernate to store a component class in a separate table?</p> <p>Take the following example:</p> <pre><code>&lt;class name="test.ClassA"&gt; &lt;property name="propA"/&gt; &lt;component name="componentProp" class="test.ClassB"&gt; &lt;property name="propB"/&gt; &lt;/component&gt; &lt;/class&gt; </code></pre> <p>This maps to a table called <code>MyClass</code> with two columns <code>propA</code> and <code>propB</code>. What I want is to map the properties of the component to a table called <code>ClassB</code>.</p> <p>What I <em>don't</em> want to do is configure <code>ClassB</code> as an entity in itself (it has no meaningful identity outside of <code>ClassA</code>), 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 <code>ClassB</code>.</p> <p>This seems to be a gap in Hibernate's functionality - the &lt;component> mapping performs "multiple-classes-to-one-table", and &lt;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.</p> <p>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 <code>ClassB</code> 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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload