Is there something special that needs to be done to get Hibernate to cascade the saving of key values when the map itself is saved? I'm getting the error message:
net.sf.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing
when I try to session.save(obj) where the object contains a map if I don't individually save the keys of the map (via session.save(key1), session.save(key2), etc.) first.
(Cascade saves of the map's *values* work fine.)
This is how my map container is defined:
Code:
<class name="hibernate.HMap" table="HContainer">
<id name="id" unsaved-value="0">
<generator class="native"/>
</id>
<map name="map" table="HMap" cascade="all-delete-orphan">
<key column="container_id"/>
<index-many-to-many column="key_id"
class="hibernate.HMapKey"/>
<many-to-many column="value_id" class="hibernate.HMapValue"/>
</map>
</class>
The key:
Code:
<class name="hibernate.HMapKey" table="HMap_key">
<id name="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="value"/>
</class>
The value:
Code:
<class name="hibernate.HMapValue" table="HMap_value">
<id name="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="value"/>
</class>