• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Second Level Cache

 
Stephane Ekobo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using ehCache implementation for performing hibernate second level object caching. My Application needs more than one session factories, but all those factories works with the same database schema, it means that the db structure are the same but the datas stored inside are completely different.
The problem is that Hibernate use the same cache for all sessionFactories, so if I have to objects with the same keys but comming from different factories, the cache manager will think that those objects are the same, that is a bad behaviour, so what can I do to tell the cache manager that this to objects are not comming from the same session factory?
 
Jonathan Huang
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of mapping the second level cache in the mapping file, put them in each of the different config file(cfg.xml). You can then name the region name of each of the class-cache and collection-cache whatever you want.

I think that will do it for you.
 
kri shan
Ranch Hand
Posts: 1479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jonathan
Instead of mapping the second level cache in the mapping file, put them in each of the different config file(cfg.xml). You can then name the region name of each of the class-cache and collection-cache whatever you want.,


How can i do second level cache in the different config file(cfg.xml) instead of mapping file. Can you give one example/sample ?
 
Jonathan Huang
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So each different DS will need a different .cfg.xml file.

in each one you can do <class-cache> and <collection-cache> tags. Just set the region="someRegion" different in each one so that even though they're in the same JVM, they'll be looking things up from different locations.

Check out the Hib3 documentation for more details.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic