Hi all,
I have a simple parent-child relationship: Obj-Item
Obj holds a MAP of Items, where the map key is the 'name' of the Item. However, 'name' is NOT the id of the Item.
Somewhere outside my app, an item's NAME may change. What is the best way to reflect this change in my app? calling refresh(obj) doesn't work because it refreshes the items of that object, WITHOUT refreshing the keys in the map, i.e. after refresh, I get:
old name=item with new name
instead of
new name=item with new name
Thanks.
The code (outside the app) that used to update the item name is:
Code:
obj = (Obj)session.load(Obj.class, new Long(1));
item = obj.getItems().get("old name");
item.setName("new name");
session.update(sub);
Hibernate version: 3.1
Mapping documents:Code:
<hibernate-mapping>
<class name="hib_refresh1.Item" table="ITEM"
discriminator-value="hib_refresh1.Item">
<id name="id" column="ITEM_ID">
<generator class="native"/>
</id>
<discriminator column="CLASS" not-null="true" type="string"/>
<property name="val" column="VAL" not-null="true"/>
<property name="name" column="NAME" not-null="true"/>
<map name="subs" cascade="all-delete-orphan" inverse="true" lazy="false">
<key column="ITEM_ID" not-null="true"/>
<map-key formula="SUB_ID" type="long"/>
<one-to-many class="hib_refresh1.Sub"/>
</map>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="hib_refresh1.Sub" table="SUB"
discriminator-value="hib_refresh1.Sub">
<id name="id" column="SUB_ID">
<generator class="native"/>
</id>
<discriminator column="CLASS" not-null="true" type="string"/>
<property name="val" column="VAL" not-null="true"/>
<many-to-one name="item" column="ITEM_ID" class="hib_refresh1.Item"/>
</class>
</hibernate-mapping>