-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Disappearing Relationship ... cache related?
PostPosted: Mon Jan 12, 2004 12:24 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
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,


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 1:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
1) show the whole mapping ... I don't even see any <cache> element in the set mapping!
2) what happens when you use a different cache provider (say, HashtableCacheProvider)


Top
 Profile  
 
 Post subject: Update
PostPosted: Mon Jan 19, 2004 12:20 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
Here's an update on this issue. I'm still not sure if it's a bug or somehow that I'm not using Hibernate right.

Here are some things I did and how they affected the problem:

- updated to Hibernate 2.1.1, no change
- updated to ehcache 0.7, no change
- turned off caching, behavior fixed
- changed the one-to-many inverse="false" to ="true"
- turned cache back on, behavior still fixed

I happened to notice that this was one of just three one-to-many inverse="false" relationships in the whole application and the only one that was used with any frequency. That gave me a clue as the the source of the problem. I read up on what inverse really means in the one-to-many relationship, but couldn't find anything that looked wrong in the code. Every time I set a relationship I set it from both directions since these objects live a long time in the cache and the relationship has to be navigable from both ends.

So my hunch is that this is an issue with ehcache + one-to-many inverse="false". The problem showed up only after switching from JCS to ehcache with 2.1 final.

Gavin, not sure what you mean about not seeing a <cache> element. I configure the cache in the hibernate.cfg.xml file, from which I included the relevant snippets.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2004 12:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
Gavin, not sure what you mean about not seeing a <cache> element. I configure the cache in the hibernate.cfg.xml file, from which I included the relevant snippets.


No you didn't. There are no snippets from .cfg.xml. I need them.


Does the behavior change depending upon the timeouts you set in EHCache? What happens if you completely disable eviction in EHCache?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2004 1:08 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
so sorry, here are the cache settings, not too exciting:

Code:
      <class-cache class="org.me.Item" usage="read-write"/>
      <class-cache class="org.me.Category" usage="read-write"/>

      <collection-cache collection="org.me.Category.items" usage="read-write"/>


Yes, when I reduced timeToIdleSeconds and timeToLiveSeconds, the error occurred more quickly and we were better able to debug since the period was reduced.

As for disabling eviction, I didn't try that.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 9:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
OK, would you give me a very simple test case (just one association) to reproduce this (submit it to JIRA).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.