facebook

Force hibernate cache refresh? [closed]

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #222266 Reply

    sjquinn
    Member

    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

    #222298 Reply

    sjquinn
    Member

    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

    #222303 Reply

    Robert Varga
    Participant

    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

    #222304 Reply

    Robert Varga
    Participant

    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

    #222325 Reply

    sjquinn
    Member

    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.

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Force hibernate cache refresh? [closed]

You must be logged in to post in the forum log in