-->
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.  [ 9 posts ] 
Author Message
 Post subject: Enabling JCS Cache...
PostPosted: Fri Sep 05, 2003 6:16 am 
Newbie

Joined: Wed Sep 03, 2003 9:08 am
Posts: 18
Hi,

I enabled JCS caching for a couple of classes in the hibernate. When I start the server, I'm getting log statements saying Hibernate's caching class and also the logging statements by JCS, correctly showing the name of the classes for I've enabled the caching.

However, when I make a call to load the object using session.load(), hibernate is printing the SQL query that is used for fetching the object from the database.

Also, when I run hibernate in debug mode, the log statements shows as follows:

Code:

15:45:36,671 DEBUG [lru.LRUMemoryCache (get:224)] getting item from cache com.maco.common.Member for key 202
15:45:36,671 DEBUG [lru.LRUMemoryCache (get:234)] com.maco.common.Member: LRUMemoryCache hit for 202
15:45:36,671 DEBUG [lru.LRUMemoryCache (verifyCache:610)] verifycache[com.maco.common.Member]: mapContains 1 elements, linked list contains 1 elements
15:45:36,671 DEBUG [lru.LRUMemoryCache (verifyCache:612)] verifycache: checking linked list by key
15:45:36,671 DEBUG [lru.LRUMemoryCache (verifyCache:641)] verifycache: checking linked list by value
15:45:36,671 DEBUG [lru.LRUMemoryCache (verifyCache:651)] verifycache: checking via keysets!
15:45:36,671 DEBUG [control.CompositeCache (get:498)] com.maco.common.Member - Memory cache hit
15:45:36,687 DEBUG [impl.SessionImpl (doLoad:2028)] object not resolved in any cache [com.maco.common.Member#202]
15:45:36,687 DEBUG [persister.EntityPersister (load:354)] Materializing entity: [com.maco.common.Member#202]
...


After this the log statements show that hibernate is making call to the database and fetching the entity.

From the log statements it looks like cache is hit for the corresponding entity but still hibernate makes a call to database for fetching the entity. Can you please explain me what I need to configure so that Hibernate uses the JCS cache?

Regards,
Balakrishnan.

P.S: My current configuration file contains the following single line for JCS caching(with separate cache.ccf file for JCS configuration).
<jcs-cache class="com.maco.common.Member" usage="nonstrict-read-write" />


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 6:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Looks like it is not hitting an actual cached entity. Looks like it is just finding a timestamp ("soft lock") there.

You would see another message from NonstrictReadWriteCache if it fould the actual object.

Perhaps you are not completing the session/transaction correctly, so the "soft lock" is not being released.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 6:48 am 
Newbie

Joined: Wed Sep 03, 2003 9:08 am
Posts: 18
Can you please explain it a bit. Here's the scenario in which I'm got the above debug statements.

(1) Freshly start all the servers.

(2) User logs into the system. In this case a BMT session bean is used for fetching the user details from the database. Note that no transaction is used in this case. Just I'm using session.load() for fetching the user details from the user details. Also, no details are written to the database using any other beans. When the method is finished, session is properly closed.

(3) Next operation is Update user profile. In this case also, as per our logic first operation is fetching the user details from the database. I'm using the same method and fetching the user details. Since JCS caching is enabled I thought user details will be fetched from cache. But it is not happening :-(

Can you tell me due to any othe reasons(other than not properly closing the transaction/session), the "soft-lock" may happen?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 6:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Here we go again:


"note that no transaction is used"


Why does everyone seem to think that you don't need transactions for read-only operations!?

You should do *everything* in a transaction. It is faster and safer.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 7:18 am 
Newbie

Joined: Wed Sep 03, 2003 9:08 am
Posts: 18
Ok. I modified that code so that the getter methods also work inside transaction. But still the object is not fetched from the cache. :-(. I've properly checked for transaction and session closure.

Is there any mechanism available by which I can see the "soft-lock"s that are made to the cached object? (Just for debugging)

On side note, you said performing operations inside transactions make operations faster and safer. "Safer" ok. How does a transaction make fetch operations faster? Just curious :-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 7:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
I've properly checked for transaction and session closure.



I hope you read the bit in the Hibernate documentation that says you have to use the hibernate Transaction API when using the process-level cache. (This is a requirement that is relaxed in Hibernate 2.1 CVS.)

Quote:
How does a transaction make fetch operations faster? Just curious :-)



When you run a JDBC connection in autocommit mode it doesn't mean "no transaction" it means "a new transaction for every single database access".


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 7:38 am 
Newbie

Joined: Wed Sep 03, 2003 9:08 am
Posts: 18
Quote:
hope you read the bit in the Hibernate documentation that says you have to use the hibernate Transaction API when using the process-level cache. (This is a requirement that is relaxed in Hibernate 2.1 CVS.)


Oops! I'm missed the point. Really sorry for wasting your time :-(. I was using the bean's transaction. Since you said this restriction will be removed in 2.1 release, I'll use this caching once 2.1 released.

Again sorry for not reading the doc.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 7:39 am 
Newbie

Joined: Wed Sep 03, 2003 9:08 am
Posts: 18
Quote:
hope you read the bit in the Hibernate documentation that says you have to use the hibernate Transaction API when using the process-level cache. (This is a requirement that is relaxed in Hibernate 2.1 CVS.)


Oops! I'm missed the point. Really sorry for wasting your time :-(. I was using the bean's transaction. Since you said this restriction will be removed in 2.1 release, I'll use this caching once 2.1 released.

Again sorry for not reading the doc.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 7:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Dude, all you need to do is add the calls to:


Transaction tx = session.beginTransaction();
...
...
tx.commit();



Into your code.


As long as you are set up to use JTATransaction, and have a TransactionManagerLookup configured, Hibernate will intergrate cleanly with the Bean's JTA transaction.


Just try it out!


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