I have 4 classes:
Code:
public class Base{
... other attributes...
X xClass;
}
public class X{
Map yValues;
}
public class Y{
String simpleString;
List zValues;
}
public class Z{
List strings;
}
The list of the last class contains a FifthClass that has only a string as attribute. My goal is to just say save(instanceOfBase); and be ready.
To do this I have the following mapping:
Code:
<class name="Base" table="model">
...
<many-to-one name="xClass" class="X"cascade="all"/>
</class>
<class name="model.Kalender" table="kalender">
<id name="id" type="long" unsaved-value="-1">
<generator class="native"/>
</id>
<map name="yValues" cascade="all">
<key column="yIndex"/>
<map-key column="yKey" type="date"/>
<many-to-many class="Y"/>
</map>
</class>
<class name="Y">
<id name="id" type="long" unsaved-value="-1">
<generator class="native"/>
</id>
<property name="simpleString" type="string"/>
<list name="zValues" cascade="all">
<key column="id"/>
<list-index column="index"/>
<one-to-many class="Z"/>
</list>
</class>
<class name="Z">
<id name="id" type="long" unsaved-value="-1">
<generator class="native"/>
</id>
<list name="strings">
<key column="id"/>
<index column="index"/>
<composite-element class="FifthClass">
<property name="aString" type="string"/>
</composite-element>
</list>
</class>
The problem I have is when Hibernate tries to save an object of class Y there is a foreign key constraint on class X
Code:
Integrity constraint violation - no parent FK1838A41684912 table: KALENDER in statement [insert into dag (dagboek, id) values (?, null)]
I assume this has something to do with the complicated nested collections. Does anyone know how to solve this?
Class Y isn't needed anywhere else in my application so if it is usefull I can make some kind of composite element of it.
Thanks for looking at this (quite large) problem!