Thank you for your quick response. I am unable to send my persistentce.xml file today because I left the office. I think my ehcache provider is not fully working and the caching was done by infinispan. Ehcache jar was not loaded as a module but a jar in my application lib folder.
I will get back as soon as I have a much clearer vision of my issue.
I got it working.
My persistence.xml looks like this:
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" />
<property name="net.sf.ehcache.configurationResourceName" value="ehcache.xml" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.use_second_level_cache" value="true" />
The ehcache is bundled in my ear application in the lib folder. The only problem I faced was with the ehcache.xml configuration file that needed to be loaded in a config folder in jboss modules. Is there any other solution to put the ehcache.xml inside the ear ?
Two different questions I think. For the original question, how to invalidate the second level cache entries. For each persistence unit, there will be a EntityManagerFactory associated with the second level cache. You could get the EntitymanagerFactory and try to call EntityManagerFactory.getCache().evictAll(). You can enable TRACE logging for org.hibernate.SQL and see if the entities are loaded from the database or cache on the next application access.
For the other question (about ehcache.xml), where did you put the ehcache.xml file under as7/modules?
I've placed the ehcache.xml file in a configuration folder as described here:
and it worked. I was wondering where should I placed the ehcache inside my ear.