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: 2nd level Caching - Query & Criteria
PostPosted: Fri Dec 03, 2004 8:33 pm 
Beginner
Beginner

Joined: Sun Nov 07, 2004 4:19 pm
Posts: 38
Does 2nd level caching work with Query and Criteria? The javadoc doesn't say anything and the documentation is vague and scattered about this.

Dino


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 04, 2004 6:31 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Yes, if you excplicitely switch on query caching and if you use a cache implementation which suports query caching.

See the reference manul chapter 14.4. The Second Level Cache.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 04, 2004 12:08 pm 
Beginner
Beginner

Joined: Sun Nov 07, 2004 4:19 pm
Posts: 38
Thanks. I was playing around with the caching. If I used 'get' based on the id it would cache it. But if I used criteria in conjunction with the setCachable flag it would not work (still need to figure this out; I'm using Ehcache which says it has query caching).

Let me describe what I'm doing and you can probably suggest a better way of doing it. In our app, we can't just lookup an object based on the id for security reasons. It has to be the id of the object plus the id of the associated organization. The results will never change (just as if I looked up an object by id). I know in hibernate 3.0, there is a notion of a filter. Is there anything for hibernate 2 (virtually every single lookup will have this additional check of organization id).

Dino


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 05, 2004 2:49 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
For the query cache configuration look for hibernate.cache.use_query_cache in the reference manual.

You're right that you will be able to solve this in H3 with the new filters. If you can wait, you bether stop reading here :-).

I solved a similar problem in H2 by making the organization id part of the primary key.
But this gives you an other problem. Foreign keys concist of only one field, but you would like to have two, the foreign primary key and the organization id.
You could try to solve this with views (maybe you need Oracle's instead of triggers).
In H2 you can easily have <many-to-one> proerties which include the origanization id, but you have to set update=false and insert=false. There are ways to make this associations updatable again but it's a hack.

You would have to map the foreign key in an extra property, which is writable. In an Interceptor.findDirty() (!) method you would have to patch this property if the association has changed. Dont' do this if you have other options, since it doens't stick to the API doc of the Interceptor, it's based on the internal implementation of the hibernate session which might change.

HTH
Ernst


Top
 Profile  
 
 Post subject: Thanks Mate!
PostPosted: Mon Dec 06, 2004 2:20 pm 
Beginner
Beginner

Joined: Sun Nov 07, 2004 4:19 pm
Posts: 38
I got all the caching strategies working. Thanks for the other advice as well.

Dino


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.