MyEclipse Forums
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
sjquinn
Post subject: Force hibernate cache refresh? [closed]  PostPosted: Jan 06, 2005 - 01:27 AM
Registered Member
Registered Member


Joined: Jan 06, 2005
Posts: 3

My application is using Hibernate to manage a legacy object and is read-only. Updates are performed outside of Hibernate. Therefore I do not want to maintain a cache and need a fresh fetch with every query. Per documetation I tried setting query.setCacheable(false), however this did not have any effect. I also set the use_query_cache property in the hibernate config file to false as shown below:
<property name="hibernate.cache.use_query_cache">false</property>

This had no affect either.

I found additional documentation for suggesting Query.setForceCacheRefresh(), however this must be for a later release of hibernate as this method is not available from the query object I am using.

I am running Hibernate 2.1.4

Thx for your help,
Stu
 
 View user's profile Send private message  
Reply with quote Back to top
sjquinn
Post subject: One work around is sess.clear();  PostPosted: Jan 06, 2005 - 05:44 PM
Registered Member
Registered Member


Joined: Jan 06, 2005
Posts: 3

Still not clear why q.setCacheable(false) does not work, however I am now firing sess.clear() immediately before each query. Seems to do the trick for now.

I am still interested in anyone else's opions on this.

Thx,
Stu
 
 View user's profile Send private message  
Reply with quote Back to top
robvarga
Post subject:   PostPosted: Jan 06, 2005 - 07:38 PM
Quality Board
Quality Board


Joined: May 23, 2003
Posts: 351

Did you create a new session for every query, or do you reuse the sessions?

Session should not be long-lived, because it caches data... however it is a cheap object that can be created quickly...
Just create a new session for every query.

Regards,

Robert Varga
 
 View user's profile Send private message  
Reply with quote Back to top
robvarga
Post subject:   PostPosted: Jan 06, 2005 - 07:41 PM
Quality Board
Quality Board


Joined: May 23, 2003
Posts: 351

Btw, Query.setCacheable sets whether the created PreparedStatement should be cacheable (kept for reuse), as far as I know...

And certain queries just return ids to the server, and the objects themselves are instantiated via the cache, so if they are found in the cache, you got the cached state, not the database state.

Regards,

Robert Varga
 
 View user's profile Send private message  
Reply with quote Back to top
sjquinn
Post subject:   PostPosted: Jan 07, 2005 - 04:28 AM
Registered Member
Registered Member


Joined: Jan 06, 2005
Posts: 3

Thank-you Robert. That was the issue. I was not managing the session properly. As you noted the session should live for the duration of the transaction. I was being careless dealing with a read-only use case and was inappropriately re-using the session.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits