I have a one-to-many relationship (one Brand has many BrandTexts), and have represented this relationship in Brand's cfg.xml:
Code:
<set name="texts" lazy = "true">
<key column="brand_id"/>
<one-to-many class="BrandText"/>
</set>
Because I usually want to access the data in BrandText (columns text_key and text_value) as key-value pairs, I also have a Map element in Brand's cfg.xml:
Code:
<map name="textMap" lazy = "true" inverse = "true"
table="brand_text"
schema="dbo"
order-by="text_key">
<key column="brand_id"/>
<map-key column="text_key" type="string"/>
<element column="text_value" type="string"/>
</map>
Although I'm not sure whether this is the best way to do this, it works OK.
When I add 2nd level caching for Brand and its texts and textMap properties in hibernate.cfg.xml:
Code:
<class-cache class="Brand" usage = "read-write"/>
<class-cache class="BrandText" usage = "read-write"/>
<collection-cache collection="Brand.texts" usage = "read-write"/>
<collection-cache collection="Brand.textMap" usage = "read-write"/>
It does all cache OK. However, if I update a BrandText object, although this change gets reflected in the texts Set, the values in the textMap Map continue to have their old, stale values.
Is there any way I can make sure that Brand's textMap Map has its values refreshed when a BrandText object is updated?
Thanks,
Jonny