views:

2500

answers:

2

To make it clear and easy, I have two projects: 1. An Entity project where there are all the entity classes in this project. 2. An project that contains a main() function to run the application, My ehcache.xml is placed in the class path of this project.

My problem is: I can change the defaultCache element of ehcache.xml and I can see changes from the SQL log file. But I think the Hibernate only read my defaultCache element, because whatever I change in the cache element of a specific entity of ehcache.xml, there won't be any changes in the SQL log.

For example: If I set the maxElementsInMemory of defaultCache element to 0, whatever I set the maxElementsInMemory of the cache element of a entity to 100 or 0, there won't be any that entity cached in the second level cache. If I set the maxElementsInMemory of defaultCache element to 100, whatever I set the maxElementsInMemory of the cache element of a entity to 100 or 0, there are always be that entity cached in the second level cache.

So I think maybe the name attribute of the cache element of a entity is wrongly set and cannot be read from Hibernate?

+1  A: 

I found where my problem is. I'm using ehcache as cache provider. In the ehcache.xml,I think the defaultCache element is also used for ALL THE QueryCaches too, if I didn't set the standardQueryCache element. So it's not important whether or not I set the maxElementsInMemory of to "0", because all the QueryCache are using the defaultCache region. But setting the maxElementsInMemory of to "0" can definitely help to disable the sencond-level cache of that entity when using EntityManager.find() function.

keweishang
A: 

PLEASE, read the documentation. In case of "maxElementsInMemory" setting, a value of "0" has a special meaning - unlimited. So instead of getting no cache at all, you're caching everything.

Marcin Sciesinski