Hi all.
This post is long.
Hibernate assigns wrong id's to a cascaded object, so it could never be loaded correctly.
The mappings are here:
Code:
<!-- CONTENT -->
<class
dynamic-insert="false"
dynamic-update="false"
name="com.zzz.contentManagement.model.Content"
>
<id
name="id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="native" />
</id>
<property name="created" type="java.util.Date" not-null="true"/>
<property name="author" type="java.lang.String"/>
<!-- relations -->
<set name="relations">
<key column="id"/>
<one-to-many class="com.zzz.contentManagement.model.Relation"/>
</set>
<!-- translations -->
<map name="translations" cascade="all">
<key/>
<!-- indexed by language id (see Locale) -->
<index column="localeId" type="string"/>
<one-to-many class="com.zzz.contentManagement.model.Translation"/>
</map>
<!-- TRANSLATION -->
<class
dynamic-insert="false"
dynamic-update="false"
name="com.zzz.contentManagement.model.Translation"
>
<id
name="id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="native" />
</id>
<map name="KeyValues" table="KeyValues" cascade="all">
<key foreign-key="id"/>
<index column="translationKey" type="string"/>
<element column="value" type="string"/>
</map>
</class>
The KeyValues table is the problem, the data there does not match with the id in Translation table !!!
The test code is here:
Code:
Resort resort = new Resort();
Translation trans_EN = new Translation();
trans_EN.getKeyValues().put("name_short", "Los Cristianos");
resort.addToTranslations("EN",trans_EN);
com.zzz.util.log.LogUtil.getDebugLogger().debug("Saving "+resort);
Long key = itfModel.saveNewContent(resort);
Content content = itfModel.getDraftContent(key);
com.zzz.util.log.LogUtil.getDebugLogger().debug("EN = "+content.getMessage("description_short","EN"));
This shows null, the key inserted into the DB is 1, and the correct key should be 2.
This is really frustrating, so i'm thinking about suicide, as told in this procedure
http://www.msu.edu/~couilla3/ninja/seppuku.htm
Please, don't let me do it :)
Hibernate version = hibernate-2.1.4
Java = 1.4.2