I have these two entities:
Code:
<hibernate-mapping>
<class name="com.openkm.dao.bean.Translation" table="OKM_TRANSLATION">
<property name="module" column="TR_MODULE" length="127" not-null="true"/>
<property name="key" column="TR_KEY" length="127" not-null="true"/>
<property name="text" column="TR_TEXT" not-null="true"/>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="com.openkm.dao.bean.Language" table="OKM_LANGUAGE">
<id name="id" column="LG_ID" length="8"><generator class="assigned"/></id>
<property name="name" column="LG_NAME" length="127" not-null="true"/>
<property name="imageContent" column="LG_IMAGE_CONTENT" type="text" not-null="true"/>
<property name="imageMime" column="LG_IMAGE_MIME" length="127" not-null="true"/>
<set name="translations" table="OKM_TRANSLATION" order-by="TR_KEY asc" cascade="all-delete-orphan" lazy="false">
<key column="TR_LANGUAGE"/>
<one-to-many class="com.openkm.dao.bean.Translation"/>
</set>
</class>
</hibernate-mapping>
When the table "OKM_TRANSLATION" is created, another column called "TR_LANGUAGE" is created to manage the relation. Well, I need to change the "Translation" mapping to have a composite primary key and following the Hibernate In Action 8.3.1 get this mapping (a little weird for me). The hint is that the "TR_LANGUAGE" field should be included in the primary key:
Code:
<hibernate-mapping>
<class name="com.openkm.dao.bean.Translation" table="OKM_TRANSLATION">
<composite-id name="translationId" class="com.openkm.dao.bean.TranslationId">
<key-property name="module" column="TR_MODULE" length="127"/>
<key-property name="key" column="TR_KEY" length="127"/>
<key-property name="languageId" column="TR_LANGUAGE" length="8"/>
</composite-id>
<property name="text" column="TR_TEXT" not-null="true"/>
<many-to-one name="language" class="com.openkm.dao.bean.Language" column="TR_LANGUAGE" insert="false" update="false"/>
</class>
</hibernate-mapping>
When I try to insert "Translations", Hibernate throws an error because column 'TR_LANGUAGE' cannot be null, but it is not null (at least I put a value on it). I'm lost, any hint?