-->
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.  [ 2 posts ] 
Author Message
 Post subject: ReadWrite Cache not finding an object on first read
PostPosted: Thu Sep 27, 2007 10:32 am 
Newbie

Joined: Mon Sep 24, 2007 8:11 am
Posts: 16
Hibernate version:3.2.1

Ehcache version:1.2.3

Postgres 8.0.12

I have modified a set of persistent objects in my Hibernate-enabled application to use the READ_WRITE CacheConcurrencyStrategy.
My objects consist of:
User
User.Container
User.Container.Collection of XXX objects
an XXX object is a graph of 8-10 other objects - all of which use
the READ_WRITE annotation

I'm seeing the following behavior:
- On a create of XXX, all of the objects are loaded into the 2nd level cache
(ehcache). (this is what I expect) I've verified this by looking up cache
statistics for the individual caches - I'm seeing this in a controlled
environment where my tests are creating and reading the objects
one at a time.

- When I first read the XXX collection after it's been created, Hibernate
performs a read from the database. This is unexpected behavior
From the Hibernate logging I see (in ReadWriteCache.java):
- Cache lookup User
- Cache hit
- Cache lookup User.Container
- Cache hit
- Cache lookup User.Container.Collection
- Cached item was locked

I assume that it is this last condition that causes the database read.

After a slight pause in the logging I see a series of:
- Caching XXX
- Item was already cached
for each object in the XXX graph.

Subsequent reads after the inital read come directly from the cache and bypass the database lookup.

The logging during the subsequent reads indicate a cache hit for the
User.Container.Collection collection and there is no pause in the
log following that cache hit.

Looking at the code in ReadWriteCache, it appears to me that the call to
lockable.isGettable(txTimestamp) is failing - which indicates the passed in timestamp is >= the timestamp on the cached item.
But I am pausing several seconds between the create and the read, so that doesn't seem to make sense - the timestamp is set when the cached object is created and never modified.

Can anyone explain why this could be happenning?
I'm trying to insure that I always get the cached objects, when available,
for performance purposes.

Thanks


Top
 Profile  
 
 Post subject: Eager loading fixes it
PostPosted: Thu Sep 27, 2007 11:26 am 
Newbie

Joined: Mon Sep 24, 2007 8:11 am
Posts: 16
I changed the annotation on the collection that was causing the
database lookup from FetchType.LAZY to FetchType.EAGER and
it looks like this solved my problem. Initial and subsequent reads
all bypass the database and come from the cache, as I expected.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.