I have a Profile object, that I would like to contain a hashmap of ProfilePreference objects, where the hashmap key, is an identifier for the preference_id- located in a lookup table.
When creating the profile initially, Hibernate does a fine job of inserting records for the map, and reading them back. However, when I update one of the objects in the map, hibernate doesn't seem to notice the changes to the child "PRofilePreference" object. Cascade is all-delete-orphan.
Here's some snippets of relevent code-
The map declaration on the profile object in mapping file:
Code:
<map name="profilePreferences" table="PROFILE_PREFERENCE" lazy="true" cascade="all-delete-orphan" >
<key column="profile_id"/>
<index column="profile_preference_type_code" type="java.lang.Integer"/>
<one-to-many class="com.housing.domain.ProfilePreference" />
</map>
ProfilePreference class (the one in the hashmap)
<class name="com.housing.domain.ProfilePreference" table="PROFILE_PREFERENCE" >
<id name="id" type="java.lang.Integer" column="ID">
<generator class="identity" />
</id>
<property name="value" type="java.lang.String" column="VALUE" not-null="true" length="50" />
<property name="creationTimestamp" type="java.sql.Date" column="CREATION_TIMESTAMP" not-null="true" length="19" />
<property name="modTimestamp" type="java.sql.Date" column="MOD_TIMESTAMP" length="19" />
<property name="updateProfile" type="java.lang.Integer" column="UPDATE_PROFILE" not-null="true" length="11" />
<property name="profilePreferenceType" type="java.lang.Integer" column = "PROFILE_PREFERENCE_TYPE_CODE" not-null="true" />
<!-- associations -->
<!-- bi-directional many-to-one association to Profile -->
<many-to-one name="profile" class="com.housing.domain.Profile" not-null="true">
<column name="PROFILE_ID" />
</many-to-one>
update code from the parent "Profile" object:
ProfilePreference pref = (ProfilePreference)this.profilePreferences.get(new Integer(prefValues[i].getLabel()));
if (pref != null)
{
profilePreferences.remove(new Integer(prefValues[i].getLabel()));
pref.setValue(prefValues[i].getValue());
pref.setModTimestamp(now);
pref.setUpdateProfile(updater.getId());
pref.setProfile(this);
profilePreferences.put(new Integer(prefValues[i].getLabel()), pref);
}
Thanks!
James