I have a object1 which have an other object2 who attribute, and in the base I want to save with the object1 the idkey to the other object2.
the configured hibernate object1 is:
<hibernate-mapping> <class name="Object1" table="Object1"> <id column="name" name="name" unsaved-value="0"> <generator class="native"/> </id> <property column="disable" name="disable"/> .. <property column="xxx" name="xxx"/> <one-to-one name="Object2Id" class="Object2" foreign-key="idObject2" cascade="all"/> </class> </hibernate-mapping>
and the object2 is:
<hibernate-mapping> <class name="Object2" table="Object2"> <id column="idObject2" name="idObject2" unsaved-value="0"> <generator class="native"/> </id> <property column="name" name="name"/> </class> </hibernate-mapping>
I want that when I save the object1, save the object2 too, and put in the attribute Object2Id the key to the table Object2
but, when I do that, hibernate first do, save Object1 and a update Object2 and this throws exception because the Object2 doesn`t exist yet. I want that do a save Object2, not a update!
Who can I do this?? What is wrong? Thanks.
|