-->
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.  [ 8 posts ] 
Author Message
 Post subject: How to force Hibernate to get record only from its cache
PostPosted: Thu Nov 13, 2003 12:15 pm 
Newbie

Joined: Thu Nov 13, 2003 12:05 pm
Posts: 3
Hi, guys,

I understand that Hibernates caches records that it already retrieved. Next time when it needs to retrieve a record, it looks for it in the cache first, if it's not in there, query the database.

How to force Hibernate to look for the record ONLY in the cache. If it's not in there, forget it, don't query the database.

My issue is that the record I query is not really existing. Even if Hibernate has cached all records, it still can't find it in the cache so it goes to query the database, which will degrade the performance.

Thanks.

George


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 12:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ah current Hibernate CVS keeps track of "failed loads", if thats what you are asking for.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 12:42 pm 
Newbie

Joined: Thu Nov 13, 2003 12:05 pm
Posts: 3
Thanks for quick reply. My issue is that I don't know if a certain record is in the database so I do a find query. If that record is not really existing in the database, hibernate can never find it in the cache, so it goes to query the database. If I unfortunately has a loop of 100 times, hibernate can't find the record in the cache so it will query the database 100 times. Is there a way to force hibernate to query the cache only. If it's not in the cache, forget it, don't query the database, just return null.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 12:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
A query? As in HQL?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 12:51 pm 
Newbie

Joined: Thu Nov 13, 2003 12:05 pm
Posts: 3
I am using someting like
session.find("from Symbol as rst where id =?");

where ? equals say, 10. For some reason, for instance, I have a loop of 100 times on this but id#10 is not really in the database, so

for(int i = 0; i < 100; i++)
session.find("from Symbol as rst where id =?");

will query the database 100 times. Is that right?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 1:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
ummm yeees. of course.

In 2.1, you *could* use the query cache. But that would be a workaround for what looks like just a bad application design.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 12:22 pm 
Newbie

Joined: Fri Nov 14, 2003 12:09 pm
Posts: 6
Location: Paris
I have a similar problem:
In a Web application i want to retrieve an object from the cache after a session reconnect.
I dont want to reload the object from the database, but I forgot the reference and want only to retrieve it from the id.
New with hibernate, may be I miss something !
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 12:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
so, use the second-level (jcs) cache.


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