Hello,
I have a bidirectional association problem.
The association is one-to-many: 1 "Projekt" has 0..* "Kunden".
Now consider the mapping for "Projekt":
Code:
<set name="kunden" cascade="all" lazy="true">
<key column="id" />
<one-to-many class="Kunde"/>
</set>
The "Kunden"-Klass itself consists of a composite-key (created by MyEclipse, but I found no better solution):
Code:
<class name="Kunde" table="kunden">
<composite-id name="id" class="KundenKey">
<key-many-to-one name="projekt" column="projekte_Id" class="Projekt"/>
<key-many-to-one name="firma" column="firmen_Id" class="Firma"/>
<!--
<key-property name="projekt" column="projekte_Id" />
<key-property name="firmen" column="firmen_Id" />
//-->
</composite-id>
As you can see there it's a unidirectional association.
Now to the problem.
I want to make an object of the class "Projekt" persistent:
Projekt p = new Projekt(); // parent class
p.setKunden(kunden); // add the "children"
res = addProject(p); // does: session.save(p);
1) If I have cascade="all" or "all-delete-orphan", the projekt is inserted (thats OK), but then Hibernate stucks and I don't get any response from the webserver. No error messages either.
2) If I have cascade="save-update" (or even the same with "none"), the projekt is inserted (thats OK as well). Additionally, Hibernate tries to UPDATE rows in the Kunden-table instead of INSERTing them!
This rises an error, of course, because there are no rows to update available. They have to be inserted first.
Does any have some advice?
Or, do I have to insert the kunden-class manually?
Actually I'm looking for the parent-children-solution.
Thanks for your help,
George