- This topic has 4 replies, 2 voices, and was last updated 19 years, 10 months ago by sjquinn.
-
AuthorPosts
-
sjquinnMemberMy 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
sjquinnMemberStill 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
Robert VargaParticipantDid 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
Robert VargaParticipantBtw, 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
sjquinnMemberThank-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.
-
AuthorPosts