-->
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.  [ 1 post ] 
Author Message
 Post subject: automatic query cache invalidation
PostPosted: Tue Sep 23, 2008 9:05 am 
Newbie

Joined: Tue Sep 23, 2008 8:04 am
Posts: 1
hi
I'm pretty unexperienced with Hibernate and I'm trying to understand how hibernate query cache really works. I have a persistent entity called Container which can have many Items. I wanted to have all the items cached:
Code:
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
class Item {
  // the code ...
}

class Container {
  @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
  public List<Item> getItems() { ... }
 
  // rest of the code ...
}

The problem which I have noticed is that when I:
1) read some Containers from the db into memory (together with the corresponding items)
Code:
       String hql =
          "from Container c left join fetch c.items where c.type = 1";
       List<Item> list = hibernateTemplate.find(hql);

2) insert new Item for a chosen Container
Code:
       hibernateTemplate.save(item)

3) repeat the first step
then in the 3rd step I cannot see the item I have inserted in the second step.
The only way I have found to make it work was to manually clean the cache after inserting new items:
Code:
  sessionFactory.evictCollection("Container.items", updatedContainerId)

My gut feeling tells me that Hibernate should do such a cache invalidation automatically. Has anyone seen it working? Am I doing something wrong or is it just not supported?

Thanks in advance for the answer.
Greetings
Tom


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.