-->
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.  [ 2 posts ] 
Author Message
 Post subject: Question about query cache and versioned entities
PostPosted: Wed Sep 12, 2007 3:22 pm 
Newbie

Joined: Wed Sep 12, 2007 3:07 pm
Posts: 1
Hibernate version: 3.2.2

Name and version of the database you are using: Postgres 8.2.4

I have a persistent versioned entity loaded in hibernate session A. I make a change to this entity in hibernate session B. I can see that the version number of this entity has been incremented after the update in session B. I reload the entity (via a HQL query.list()) in hibernate session A, but it obviously is pulling the entity out of the cache, as the changed data is not represented. My cache mode is set to NORMAL.

Question one:
I guess I assumed that the reload of the entity in session A would pick up the changes made in session B, because of the version change. Clearly Im wrong and do not understand what specifically occurring in this case. Can someone explain why I wouldnt pick up the changes to the versioned entity in this case?

Question two:
How can I achieve the desired behavior and still realize the maximum performance optimizations afforded by the cache? I dont want to have to reload all the objects returned by the query, only the ones that have been updated.

Thanks

[EDIT]
BTW, the two sessions in the example above are constructed by two different session factories.

Also, I tried setting the CacheMode to REFRESH for the second query, but the results still did not reflect the changes in the DB. I have to clear the session to get the data to reload. I must be missing something here.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 12, 2007 7:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
1) Version attribute is for Optimistic locking - it is designed to be checked when you perform the Update since the data as read previously could be stale (which is what you have here).

2) Cache synchronisation due to updates from (multiple) external connections (using hibernate or otherwise) is outside of the scope of hibernate. There are various approaches that you can implement, eg, triggers and JMS messages or some clustered cache solution etc, what you as the architect need to consider is whether the extra cache management costs are greater than the benefit of the (closer to) full synched data cache.


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