0

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?

2
  • This might be an issue with the Hibernate configuration. It would help if you could include the hibernate.cfg.xml (or hibernate.properties) file, as well as at least one Hibernate mapping file (or the Java class w/annotations). Commented Jun 2, 2009 at 18:14
  • Thank you, 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 <cache name="business.entity.car"...> to "0", because all the QueryCache are using the defaultCache region. But setting the maxElementsInMemory of <cache name="business.entity.car"...> to "0" can definitely help to disable the sencond-level cache of that entity when using EntityManager.find() function. Commented Jun 3, 2009 at 7:39

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.