-->
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: ORDER BY and Cache
PostPosted: Tue Jan 13, 2004 5:22 am 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Could it be that using the ORDER BY clause in queries disables caching for these queries completely?

I am experiencing relatively harmless queries like "FROM users ORDER BY name" missing any cache and accessing the DB every time.

I have configured ehcache for second level and switched on the query cache. Each class of my object model has got the "nonstrict-read-write" cache property set.

Regards,

Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 5:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Are you really using query caching? Enabling the class level cache by default does not cache any query results at all - you must explicitly enable query caching.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 1:45 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
I have enabled

<property name="cache.use_query_cache">true</property>

and have added

* @hibernate.cache usage="nonstrict-read-write"

to the XDoclet class level tags of every persistent class. EHCache is configured by default. Log messages reveal that both EHCache and Query Caches are being initialized.

Here is my statement:

FROM GameInvitation AS i
WHERE i.user = ?
AND i.game.status = 'forming'
ORDER BY game_id

I am executing it with the following code

List results = session.createQuery(hql).setCacheable(true).setParameter(0, user, Hibernate.entity(User.class)).list();

On consecutive invocations (in different Sessions, maybe thats the problem) with the same parameter (user), I always get the following SQL output:

Hibernate: select gameinvita0_.id as id, gameinvita0_.game_id as game_id, gameinvita0_.user_name as
user_name from game_invitations gameinvita0_, games game1_ where (gameinvita0_.user_name=? )AND(game
1_.status='forming' and gameinvita0_.game_id=game1_.id) order by game_id

Is there anything I have forgotten?

Regards,

Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 1:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
woops ... ignore this


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 1:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Sometimes it takes a certain delay before the query cache can be utilized (due to the timestamping scheme)


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.