-->
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 Problem
PostPosted: Thu Dec 04, 2003 6:12 am 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
I'm trying to cache the results of a very repetitive query, and am running into problems using the new query cache of 2.1 rc1.

I've configured my second-level cache (I'm using OSCache) so that it is unlimited for the time being, I've put the <cache... tag into my XML descriptor for the class, and I've made the class immutable.

I've turned on the query cache, set the query to setCacheable(true), and then I run the query. The first time I run the query, it correctly caches the results. However, the second time and any further times I run the query, it outputs the following, invalidates the cache and repopulates it.

Code:
10:01:51,728 DEBUG QueryCache:61 - checking cached query results in region: net.sf.hibernate.cache.QueryCache
10:01:51,728 DEBUG QueryCache:70 - cached query results were not up to date


For each entity, I get the following after running the query, so I'm assuming the second-level cache is working correctly:

Code:
10:01:51,938 DEBUG SessionImpl:2135 - adding entity to second-level cache


I'm using Hibernate for all access to my data - I was under the assumption that the query cache worked on the basis that it checked to see whether any updates or deletes had happened on the data using the UpdateTimestampsCache. Considering that I'm running the queries back to back, just as a simple test and no other access is going on, am I doing something fundamentally wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 04, 2003 6:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Possibly you are using SessionFactory.openSession(Connection) instead of SessionFactory.openSession().


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 04, 2003 7:52 am 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
Cheers for the prompt reply - I'm using openSession() unfortunately, and just for added info I'm currently using the internal connection pooling of Hibernate as well (just for testing purposes).

Here's the code I use for the query:

Code:
currentSession = sessions.openSession();

Query selectionQuery = currentSession.createQuery("from TestCache tc where tc.type=:type");
selectionQuery.setProperties(queryBean);
selectionQuery.setCacheable(true);
results = selectionQuery.list();


The variable sessions is a static reference to the SessionFactory object, which is created once on class instantiation.

I've tried hardcoding the type in the query as well, and that has no bearing on the issue. I've also tried changing the cache type from read-only to nonstrict-read-write just to see if that helped, but I had the same results.


Hibernate Properties File contains the following:

Code:
hibernate.dialect=net.sf.hibernate.dialect.OracleDialect
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.url=jdbc:oracle:thin:@192.168.196.2:1521:DWP2
hibernate.connection.username=test_user
hibernate.connection.password=password
hibernate.connection.pool_size=10
hibernate.cache.provider_class=net.sf.hibernate.cache.OSCacheProvider
hibernate.cache.use_query_cache=true
hibernate.show_sql=true



Object mapping file:

Code:
<hibernate-mapping>
    <class
        name="com.qxlva.TestCache"
        table="TESTCACHE"
        dynamic-update="false"
        dynamic-insert="false"
        mutable="false"
    >

   <cache usage="read-only" />

        <id
            name="id"
            column="ID"
            type="string"
            length="255"
            unsaved-value="null"
        >
            <generator class="native">
            </generator>
        </id>

        <property
            name="name"
            type="string"
            update="true"
            insert="true"
            column="NAME"
            length="100"
            not-null="false"
        />

        <property
            name="type"
            type="integer"
            update="true"
            insert="true"
            column="TYPE"
        />

        <property
            name="addressId"
            type="string"
            update="true"
            insert="true"
            column="ADDRESSID"
            length="255"
            not-null="false"
        />

    </class>

</hibernate-mapping>



As another question, I'm currently using JDK1.3.1 - I take it the query cache can be used with this JDK?

Thanks again - any help is much appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 04, 2003 7:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ah I don't know .... I'll need to debug this. The query cache is new stuff.

Submit a simple main() method to JIRA, and I should be able to find the cause in no time.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 04, 2003 8:00 am 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
Ok cheers - I'll do that now.


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.