-->
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.  [ 5 posts ] 
Author Message
 Post subject: Query Cache
PostPosted: Tue Apr 13, 2004 11:18 am 
Beginner
Beginner

Joined: Mon Mar 08, 2004 5:22 pm
Posts: 35
I read about UpdateTimestampsCache, QueryCache. But i want to be more clear about it.
Now i would like to understand how exactly cache is working.

I have one-to-many relation between Place & Person classes.
I am calling the below code twice in my test program to test performance which works good.
Each call loads Place and set of persons for the place. I am saving 400 milliseconds between calls.

-------------
query = session.getNamedQuery(findPlaceAndPeople); // see below for query
query.setCacheable(true);
query.setString("auctionId", auctionId);
resultList = query.list();
-------------


<hibernate-mapping>
<class name="com.peopleplacesmodel.model.Place" table="AUCTIONS">
<id name="ID" type="string" unsaved-value="null">
<column name="ID" sql-type="char(32)" not-null="true" />
<generator class="uuid.hex" />
</id>
<property name="NAME">
<column name="NAME" />
</property>
<property name="ADDR">
<column name="ADDR" />
</property>
<set name="person" lazy="true">
<key column="AUCTID" />
<one-to-many class="com.peopleplacesmodel.model.Person" />
</set>
</class>
<query name="findPlaceAndPeople">from Place as place where place.ID = :auctionId</query>
<query name="findPlaces">from Place as place</query>
</hibernate-mapping>

<hibernate-mapping>
<class name="com.peopleplacesmodel.model.Person" table="PRTDIRVIEW">
<composite-id name="personName" class="com.peopleplacesmodel.model.PersonPK">
<key-property name="AUCTID" />
<key-property name="PRTLNAME" />
<key-property name="PRTFNAME" />
</composite-id>
<property name="PHONE">
<column name="PHONE" />
</property>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 13, 2004 3:47 pm 
Beginner
Beginner

Joined: Mon Mar 08, 2004 5:22 pm
Posts: 35
Hello. can someone talk about this pls


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 13, 2004 9:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I'm sorry, what exactly is your question?

If you just want to know how the query cache "works", simply look at the sourcecode. Its quite straightforward.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 14, 2004 4:47 pm 
Beginner
Beginner

Joined: Mon Mar 08, 2004 5:22 pm
Posts: 35
Gavin,
Here is my question, may be with some additions to it.
Q1:
I had the following settings in my hibernate.properties.

hibernate.cache.use_query_cache true
hibernate.cache.provider_class net.sf.hibernate.cache.HashtableCacheProvider

and i am running the sql with 'query.setCacheable(true);' twice in loop to check the performace. I am assuming that my query results are cached since the response in the loop is faster the second time.

At this point i do not have "ehcache-0.6.jar" in my class path. Does this mean Cache is really working ? if so, using what type of cache ? I just some theoritical explanation.

Q2 :
Now i want to try EHCache too. Can you give me steps to set up EHCache ?

I just looked at ehcache.xml, could undestand to some extent.
I would like to set "maxElementsInMemory=1", overflowToDisk="true" and actually see the objects are written to disk.
I am looking for some example please.
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 14, 2004 5:11 pm 
Regular
Regular

Joined: Wed Mar 03, 2004 9:38 am
Posts: 70
rajoos2004 wrote:
I am assuming that my query results are cached since the response in the loop is faster the second time.


I wouldn't "assume" that. It could equally well be due to the fact that the second time the actual on-disk data is found in the operating system buffers, or that the DB itself is doing some caching.

Quote:
At this point i do not have "ehcache-0.6.jar" in my class path. Does this mean Cache is really working ? if so, using what type of cache ? I just some theoritical explanation.


You mentioned that you have configured hibernate to use HashtableCacheProvider, so I assume that Hibernate would thus use the built-in HashtableCache. AFAIK HashtableCache is basically a toy which shouldn't be used for other than testing purposes. You can check that the cache is actually working by putting the line

Code:
log4j.logger.net.sf.hibernate.cache=debug


in your log4j.properties file and watching the log output.

Quote:
Now i want to try EHCache too. Can you give me steps to set up EHCache ?


Put ehcache-x.y.jar in the classpath, and configure the ehcache.xml file.

Quote:
I would like to set "maxElementsInMemory=1", overflowToDisk="true" and actually see the objects are written to disk.


Then do that, if that is what you want to do. No need to ask for permission.

Quote:
I am looking for some example please.


The ehcache website contains some documentation about how to set it up.


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