Ah, a misunderstanding. I think this is clean, but I am having another problem now. I have two objects, one using native generator, the other foreign. Cascade is set to "save-delete", which seems to be equivilent to "all" in this case.
When I save the native object, the foreign object is cascade saved. But the native generator needs to know the pk after the object has been saved. Because the foreign object is saved under cascade, it's a chicken/egg problem.
When I set cascade="none", the objects don't actually save out, but Hibernate doesn't throw an exception either.
Code:
Inode i = new Inode();
Folder f = new Folder();
i.setObject(f);
f.setInode(i);
session.save(i);
f.setName("root");
session.save(f);
session.close();
The mappings
Code:
<hibernate-mapping>
<class
name="modules.general.entity.Folder"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="foreign">
<param name="property">inode</param>
</generator>
</id>
<one-to-one
name="inode"
class="modules.general.entity.Inode"
cascade="none"
outer-join="auto"
constrained="false"
/>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Folder.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class
name="modules.general.entity.Inode"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="native">
</generator>
</id>
<many-to-one
name="folder"
class="modules.general.entity.Folder"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="folder"
/>
<any name="object" id-type="long" cascade="save-update">
<column name="clazz" length="100"/>
<column name="gen_id"/>
</any>
</class>
</hibernate-mapping>
Any ideas? The architecture has to stay this way for a multitude of reasons that I can get into if necessary, but I'm wondering if this can be made to work.
Thanks...