I have the following relationship:
Code:
Item *-- Category
the item table has a foreign key category_id. In the java, Item has a field category, and Category has a SortedSet field items. Here are the relevant mappings:
Code:
<many-to-one
name="category"
class="org.me.Category"
column="category_id"
not-null="false"
unique="false"
cascade="none"
outer-join="auto"
/>
Code:
<!-- inverse false because FK will be set null when ItemCategory deleted -->
<set
name="items"
lazy="true"
inverse="false"
cascade="none"
sort="natural"
>
<key
column="category_id"
>
</key>
<one-to-many
class="org.me.Item"
/>
</set>
I'm also using ehcache. Here are those settings:
Code:
<cache name="org.me.Item"
maxElementsInMemory="500"
eternal="false" timeToIdleSeconds="14400" timeToLiveSeconds="21600" overflowToDisk="true"
/>
<cache name="org.me.Category"
maxElementsInMemory="500"
eternal="false" timeToIdleSeconds="14400" timeToLiveSeconds="21600" overflowToDisk="true"
/>
<cache name="org.me.Category.items"
maxElementsInMemory="500"
eternal="false" timeToIdleSeconds="14400" timeToLiveSeconds="21600" overflowToDisk="true"
/>
When I set or unset a item's category, I always set both ends of the relationship, setting the item's field and adding the item to the category's set.
Everything seems to work just fine, as it does for the numerous other many-to-one relationships that I have that are very similar to this one. However, I am experiencing mysterious data loss ... the relationship is being reset to null a certain amount of time after it is set. It is possible that it is being reset around the 4 hour timeToIdleSeconds threshold, but it certainly happens before the 6 hour timeToLiveSeconds threshold.
Just to summarize what the user experience is:
1. user associates item with category using the web tool
2. user continues working, all the time the tool indicates that the relationship is set.
3. user comes back after a few hours, or the next day, and relationship is not set.
Does anyone have any ideas what this could possibly be?
I'm using Hibernate 2.1 and the ehcache that came with it.
Thanks,