I managed to get something close to what I want by mapping
TranslatedText using a many-to-one within
Question. It works well, but I'll have to implement a custom solution to deal with orphan removal.
Ideally I'd map everything as dependend objects (components). The only thing that prevents me from doing it is that I could not find a way to properly map the translations because we need some kind of discriminator in there that is not part of the model and must be used to form a composite foreign key.
Code:
<component name="title" class="TranslatedText">
<bag name="translations" table="Translation">
<key>
<column="question_id" not-null="true">
<!--
We are missing a discriminator that would be the 'title' hard-coded string in
here and that value cannot come from the model.
-->
</key>
<composite-element class="Translation">
<property name="languageCode" type="string" column="language_code"/>
<property name="text" type="string"/>
</composite-element>
</bag>
</component>
Adding a type property to TranslatedText would probably work, but it would make the model quite ugly, having to do:
Code:
title = new TranslatedText('title', ...);
description = new TranslatedText('description', ...);
We could abstract that by creating concrete `Title` and `Description` classes, but that may potentially lead to an explosion of classes.
EDIT: I couldn't find a way to map everything as dependent objects, even with concrete distinct
Title and
Description classes.